Hello! I'm new to C and i'm trying to figure out how to move down a text file and print out only certain lines.
I know that fgets reads one line from a file but how do you skip 4 lines and then print out the 5th line?
Do i use a while loop?
eg.
Code:
FILE *ptr;
int a = 0;
char word[20];
if ((ptr = fopen("input.txt","r") == NULL)
{
printf("Cannot open file");
}
else
{
while (a < 5)
{
....don't know what to put here to skip these lines....
}
if (fgets(word,20,ptr) != NULL) ......printing the 5th line
{
printf("%s", word);
}
}
fclose(ptr);
i would just like to know what allows you to skip lines in a text file.