#include #include // This program prints the contents of a file but skips the lines // starting with # (the # symbol is sometimes used to denote comments). // // The code uses fgets to read each line into a char array called BUFFER. // BUFFER is analysed and if the first character is a # the line is not printed. // // This is similar to the previous program but correctly handles comment lines // where the # symbol is not the first character on the line (there is leading whitespace). int main() { FILE *fp; char BUFFER[1024]; int a, b; fp = fopen("text.txt", "r"); // open the file for reading if(fp == NULL) printf("File not found!\n"); else { while( fgets(BUFFER, 1024, fp) != NULL) // read at most 1024 characters from fp and store them in BUFFER { int i=0; while(isspace(BUFFER[i])) // skip the leading whitespace i++; if(BUFFER[i] != '#') // if this is not a comment line printf("%s", BUFFER); // then print it on the screen } fclose(fp); } system("pause"); }