C

fgets

1. Why to use fget?

gets has Buffer overflow vulnerability. Therefore we must use fgets

 

2. How to Use?

char buf[100] = {0};
char *p;
 
printf("input : ");
fgets(buf, sizeof(buf)-1, stdin);     // char 배열, SIZE, 입력
if((p = strchr(buf, '\n')) != NULL)
*p = '\0';
 
printf("output : %s\n",buf);

 

Back To Top