Hi ,
i am having this problem of extracting data out from txt file being seperated by ¨;¨.
Example:
How is your day?;Fine
Where are you now?;At your house
My code is as follow:
Code:
char *ques[20];
char *ans[20];
int i=0;
FILE *fp;
fp=fopen("qna.txt", "r");
if ( fp == 0 )
{
printf( "Could not open file\n" );
}
else
{
while(fgets(fileInput, sizeof fileInput, fp))
{
if(sscanf(fileInput, "%s,%s", &ques[i], &ans[i]) == 2)
{
i++;
}
}
}
fclose( fp );
The difficulties i faced was that i am not able to successfully extract the data out from the text file and stored it into both que[] and ans[].
Errors keep coming out from the "%s,%s". And i guess i might have key in the wrong placeholders..
Anyone can help ? Thanks in advance...