/*
* program to show problems with gets()
*
* this is like bad.c but there is no overflow
*
* Matt Bishop, ECS 36A
* April 12, 2024 original version
*/
#include <stdio.h>
int main(void)
{
int i = 4; /* before the buffer */
char buf[10]; /* input buffer */
int j = 5; /* after the buffer */
/*
* read the input
*/
if (fgets(buf, 10, stdin) == NULL){
printf("Didn't read anything!\n");
return(1);
}
/*
* print out result; ni=o change to i or j
*/
printf("Buffer is %s, i = %d, j = %d\n", buf, i, j);
/* done! */
return(0);
}
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |