/* * program to show a legitimate use of %n */ #include #include /* * here's the main program -- read in a * number and print it and the number of * digits in it */ int main(int argc, char *argv[]) { int a; /* input number */ int n; /* width of a */ /* prompt for an integer and catch errors */ printf("Enter an integer> "); if (scanf("%d%n", &a, &n) != 1){ fprintf(stderr, "%s: bad input value\n", argv[0]); return(1); } /* print the number and the width */ printf("Number: %d; number of digits: %d\n", a, n); }