![]() ![]() ![]() | io/scanf2.c - Illustration af brugen af scan width ved læsning af en streng. | Lektion 13 - slide 22 : 32 Program 2 |
/* Illustrates use of scan width - reading a text string */ #include <stdio.h> int main (int argc, char *argv []){ int scan_res_1, scan_res_2; char str[20]; printf("Enter a test string - at most 6 chars will be read\n"); scan_res_1 = scanf("%6s", str); printf("This string has been read: %s\n", str); printf("scanf returned: %d\n", scan_res_1); /* Now reading more of the string */ scan_res_2 = scanf("%s", str); printf("Next scanf read: %s\n", str); printf("scanf returned: %d\n", scan_res_2); }