Reading Tab Separted Text files
I am having a problem in reading a text file in which data is written in columnar format seperated by tabs
like
1 10 100
2 15 200
and i am using the following code using fscanf but when it encounters tab it enters a end of line character
#include <stdio.h>
int main()
{
FILE *textfile;
char line[80];
char Templine[80];
clrscr();
if( (textfile=fopen("test.txt", "r")) == NULL )
{
printf ("Error opening text file for reading\n");
exit(0);
}
/*read file contents*/
while( (fscanf(textfile, "\t %s", Templine) != EOF) )
{
if (strchr("\n",Templine) == NULL)
line[0] = strcat(line, Templine);
else
line[0] = "\0";
printf ("%s\n", line);
}
/*close the file*/
fclose(textfile);
getch();
}