Hi i have a text file that I am unable to read properly.
Here's what I do.
It doesn't print me the file as is. Could somebody tell me what am I doing wrong?
Thanks
Here's what I do.
Code:
/* tblD.txt */
NET06 1 --
NET25 1 --
/* se.h */
typedef struct {
char netID[7];
int hopCount;
char nextHop[2];
}Routers;
/* InitD.c */
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "se.h"
int main()
{
char buff[10];
Routers routerD;
int rdr;
int loop = 0;
FILE *fp;
fp = fopen("tblD.txt","r");
rdr = fgetc(fp);
/*read network ID*/
while((rdr == '\n') && (rdr != EOF))
rdr = fgetc(fp);
if(rdr == EOF) return 0;
while((rdr != '\n')&&(rdr!='\t') && (rdr != EOF)){
buff[loop++] = rdr;
rdr = fgetc(fp);
}
buff[loop]=0;
strcpy(routerD.netID,buff);
printf("%s",routerD.netID);
if(rdr==EOF) return 0;
loop=0;
/* read hop count
*/ while( (rdr != '\n') && (rdr !='\t') && (rdr != EOF)) {
buff[loop++] = rdr;
rdr = fgetc(fp);
if(rdr==EOF)return 0;
}
buff[loop]=0;
routerD.hopCount = atoi( buff );
printf("%d",routerD.hopCount);
printf("done");
while((rdr != '\n') && (rdr != '\t')&&(rdr != EOF)){
buff[loop++]=rdr;
rdr=fgetc(fp);
}
buff[loop]=0;
routerD.hopCount = atoi( buff );
if( rdr == EOF ) return 0;
printf("%d",routerD.hopCount);
return 1;
/*
routerD.netID = ReadFromFile
routerD.hopCount = ReadFromFile
routerD.nexthop = ReadFromFile
*/
}
It doesn't print me the file as is. Could somebody tell me what am I doing wrong?
Thanks