I have a .txt file that has the following infomation
1 "Pink" "So What"
2 "T.I." "Whatever You Like"
3 "Rihanna" "Disturbia"
tab key between the number and the string, tab key between the two strings
I have to read the file and store the file data in a table struct. My code does not do that correctly (I also have to ignore the ")
Can anybody help me?
CODE
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#define ARXEIO "test.txt"
struct list
{
int number;
long singer[80];
long song[800];
};
struct list A[20];
int i=0;
int c;
int main(int argc, char *argv[])
{
FILE *fp; char ch; int count=0;
if ((fp=fopen(ARXEIO, "r"))==NULL)
{
printf ("error in opening file %s", ARXEIO); exit(1);
}
else
{
printf("File opened successfully.\n");
}
for (i=0;i<20;i++)
{
fscanf(fp,"%d",&A[i].number);
while ((ch=fgetc(fp))==('\t'|'"'));
fscanf(fp,"%s",&A[i].singer);
while ((ch=fgetc(fp))==('\t'|'"'));
fscanf(fp,"%s",&A[i].song);
while ((ch=fgetc(fp))==('"'|'\n'));
printf("%d %s %s %d\n",A[i].number,A[i].singer,A[i].song,i);
}
while (getchar() !='e');
}