/* program illustrating several input cases */ #include int main () { int i = 5; //int j = 7; char a [10] = "abcdefghi"; char ch1 = 'x'; char ch2 = 'y'; char ch3 = 'z'; //read two integers in same scanf printf ("test reading two integers with same scanf\n"); printf (" enter two integers: "); scanf ("%d %d", &i, &j); printf ("i = %d\n", i); printf ("j = %d\n", j); //read two integers in successive scanf printf ("test reading two integers with successive scanf\n"); printf (" enter two integers: "); scanf ("%d", &i); scanf ("%d", &j); printf ("i = %d\n", i); printf ("j = %d\n", j); //read integer and string //both %d and %s skip over initial white space printf ("test reading an integer and a string with same scanf\n"); printf (" enter integer and string: "); scanf ("%d%s", &i, a); // same as "%d %s" printf ("i = %d\n", i); printf ("a = %s\n", a); //read integer and 3 characters // adding " " after %d or before or after %c skips over white space printf ("test reading an integer and 3 characters\n"); printf (" enter integer and 3 characters: "); scanf ("%d", &i); scanf ("%c", &ch1); scanf ("%c", &ch2); scanf ("%c", &ch3); printf ("i = %d\n", i); printf ("ch1 = '%c'\n", ch1); printf ("ch2 = '%c'\n", ch2); printf ("ch3 = '%c'\n", ch3); return 0; }