They're called state machines
Code:
#include <stdio.h>
#include <string.h>
int main()
{
enum { DO_INIT, DO_TIME, DO_COORDS, DO_DATA } state = DO_INIT;
char buff[BUFSIZ];
FILE *fp = fopen("words.txt", "r");
while (fgets(buff, BUFSIZ, fp) != NULL) {
switch (state) {
case DO_INIT:
printf("Init line=%s", buff);
if (strncmp(buff, "TIME", 4) == 0) {
state = DO_TIME;
}
break;
case DO_TIME:
if (strncmp(buff, "COORDINATES", 11) == 0) {
state = DO_COORDS;
} else {
printf("Time line=%s", buff);
}
break;
case DO_COORDS:
if (strncmp(buff, "DATA", 4) == 0) {
state = DO_DATA;
} else {
printf("Coord line=%s", buff);
}
break;
case DO_DATA:
printf("Data line=%s", buff);
break;
}
}
fclose(fp);
return 0;
}
Just replace the printf() calls with sscanf() converting the data as you see fit.