instead of fscanf() , read the lines with fgets() and use sscanf() to replace fscanf() .
char s1[13], s2[4], s3[17], s4[43]; char line[1000]; while (fgets(line, sizeof line, stdin)) { if (*line == '#') continue; if (sscanf(line, "%12s%3s%16s%42s", s1, s2, s3, s4) != 4) { } else { } }
source share