Hi
I am writing the c code to open text file, read the line and break the string if there is a white space and put them into two different arrays.
But I want to know how to detect the blank line and skip to another line and do the same thing. Below is my code. Attached is the text file that I want to get the data from
Code:
void main(void)
{
char buffer[1000] ;
char *line;
char *token;
char *breaks = " ";
FILE *fstream = fopen("try1.txt","r");
if(fstream == NULL)
{
printf("\n file opening failed ");
}
do
{
line=fgets(buffer, 100000, fstream);
printf("\nline = %s", line);
/* token = strtok(line, breaks);
while(token != NULL)
{
printf("\ntoken = %s", token);
token = strtok(NULL, breaks);
} */
token = strtok(line, breaks);
printf("\ntoken = %s", token);
token = strtok(NULL, breaks);
printf("\ntoken = %s", token);
token = strtok(NULL, breaks);
//printf("\ntoken = %s", token);
}
while (line != NULL);
fclose(fstream);
}