// FILE: testmp4.cxx #include #include // This sample program uses standard C i/o to read an input // file for MP 4 and 5 until the end of file and with possibly // missing fields. int main () { int temp, i, a, b; char one, two[16], dummy[2]; // The following lines get rid of the initialization // of course section numbers. cin >> temp; for (i=1;i<=temp;i++) { cin >> a >> b; cin.ignore(100,'\n');} // This section reads in the data lines until the END OF FILE // according to the specified format: // the first %c corresponds to 1 character put into variable one (code) // the second %c corresponds to the blank put into variable dummy // the %15c corrresponds to the 15 spaces allocated for the name // and goes into variable two (no & needed in scanf since two is // an array which automatically is call by reference) // the %5d corresponds to the 5 spaces needed for the decimal (integer) // course number // while(scanf("%c%c%15c%5d\n",&one,dummy, two, &temp) != EOF) { // add the null character to end the passanger name character string. two[15]='\0'; cout << one << " " << two << " " << temp << endl; // the following resets temp to 0 in case a value is missing temp = 0; } // end of file cout << "that's all folks!" << endl; return 0; }