/* * brkloop2.c */ #include int main(void) { char cc; // declare char cc int count, q_flag; // declare int's count and q_flag count = q_flag =0; // initialize the int variables to zero while ( (cc=getchar()) != EOF ) // assign stdin to cc // until cc contains an EOF, // execute loop { if ( cc == '\n') // test for newline { break; } if ( cc == 'q' ) // test for a q { q_flag = 1; // set flag to 1, found 1 flag break; // exit if loop } count = (count +1); // increment counter } if ( q_flag == 1 ) { printf("There were %d characters for the first 'q'\n", count); } else { printf("There were no 'q's in the input\n"); } return 0; }