/*fscanf.c Illustrates use of fscanf() with a limit in the format string to avoid buffer overflow vulnerability */ #include /* for printf definition */ #include /* EXIT_SUCCESS */ #include int main() { int i; char buffer[10]={'\0'}; /* init first char to null - not required - just illustrating how to do it */ printf("Enter a string of a dozen or so chars: "); fflush(stdout); fscanf(stdin, "%10s", buffer); printf("\n\t\tchar\tascii\n"); for (i=0 ; i < 10 ; ++i) printf("buffer[%d]\t%3c\t%3d\n",i, buffer[i],buffer[i]); return EXIT_SUCCESS; }