#include #include int main ( ) { char c; char imageType[3]; int width, height, maxIntensity; //read magic number scanf ( "%s", imageType); //Stop if image type is not P6 if (strcmp(imageType,"P6") != 0) { printf("Bad image format. Check image format and run again\n"); exit(1); } //Read and discard characters till you see a newline do { c = fgetc(stdin); } while ( c != '\n'); c = fgetc(stdin); //Read next character. This may be the # character if ( c == '#') { //file has a comment //Read and discard characters till you see a newline do { c = fgetc(stdin); } while ( c != '\n'); } else {// file has no comment ungetc(c, stdin); } scanf("%d %d", &width, &height); scanf("%d", &maxIntensity); printf("P5\n"); printf("%d %d\n", width, height); printf("%d\n", maxIntensity); }