Hello everyone,
I am trying to store data in a struct. However it doens't set the values.
I read from a text file the values below and I've also included my code for your review. I've removed the pointers from my structure.
Would some one please advise. It's really urgent!!
Thanks
I am trying to store data in a struct. However it doens't set the values.
I read from a text file the values below and I've also included my code for your review. I've removed the pointers from my structure.
Code:
=====
NET09 1 --
NET10 1 --
=====
#include <stdio.h>
#include <stdlib.h>
void main()
{
int loop = 0;
typedef struct {
char netID[7];
int hopCount;
char nextHop[2];
}Routers;
FILE *fp;
FILE *fp1;
char arr[50];
Routers router1[5];
Routers router2[5];
fp = fopen("tblE.txt","r+");
for(loop=0;loop<5;loop++)
{
fscanf(fp,"%s\t%d\t%s\n",&(router1[loop].netID)[loop],&(router1[loop].hopCount),&(router1[loop].nextHop)[loop]);
}
fclose(fp);
loop=0;
for(loop=0;loop<5;loop++)
{
printf("%s\t%d\t%s\n", router1[loop].netID,router1[loop].hopCount,router1[loop].nextHop);
}
/* memcpy(&router1,&router2,sizeof(ROUTERS));
*/
router2=router1;
loop=0;
for(loop=0;loop<5;loop++)
{
printf("%s\t%d\t%s\n", router2[loop].netID,router2[loop].hopCount,router2[loop].nextHop);
}
fp1=fopen("test.Txt","w");
loop=0;
for(loop=0;loop<5;loop++)
{
fprintf(fp1,"%s\t%d\t%s\n", router2[loop].netID,router2[loop].hopCount,router2[loop].nextHop));
}
close(fp1);
Thanks