/* scanf */ #include <stdio.h> main() { char buf[256]; int i; while(1) { printf("終了は Ctrl+C \n"); printf("Input number: "); scanf("%d", &i ); printf("%d\n", i ); } } /* scanf1.c */
/* scanf */ #include <stdio.h> main() { char buf[256]; int i; while(1) { printf("終了は Ctrl+C \n"); printf("Input string: "); scanf("%s", buf ); printf("%s\n", buf ); } } /* scanf2.c */
/* scanf */ #include <stdio.h> main() { char buf[256]; int i; do { printf("終了は Ctrl+C \n"); printf("Input number: "); } while( scanf("%d", &i ) != 1 ); printf("%d\n", i ); } /* scanfd1.c */
/* scanf */ #include <stdio.h> main() { char buf[256]; int i; while(1) { printf("終了は Ctrl+C \n"); printf("Input number: "); gets( buf ); sscanf( buf, "%d", &i ); printf("%d\n", i ); } } /* scanf3.c */
/* scanf */ #include <stdio.h> main() { char buf[256]; int i; do { printf("終了は Ctrl+C \n"); printf("Input number: "); gets( buf ); } while( sscanf( buf, "%d", &i ) != 1 ); printf("%d\n", i ); } /* scanfd3.c */