/* * simple program using scanf to read an integer * it has problems * * Matt Bishop, ECS 36A * * April 22, 2024 * first version */ #include <stdio.h> /* * the program */ int main(void) { int n; /* what is read */ /* try to read an integer, looping until you do */ while(scanf("%d", &n) != 1){ /* you didn't; report an error */ fprintf(stderr, "Enter a positive integer\n"); } /* say what was read, and quit */ printf("I read %d\n", n); return(0); }
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |