我试图操纵字符串,所以我用获取。但当我阅读this时,我发现获取是危险的,不应该使用。所以我打开fgets,但似乎程序逃脱 fgets线???任何想法如何解决它
#include <stdio.h>
int
main (int argc, char *argv[])
{
char message[200];
int chx;
puts("===[0]ENCODE===");
puts("===[1]DECODE===");
HERE:
printf("$>\t");
scanf("%d", &chx);
if(chx != (0) && chx != (1)) goto HERE;
printf("ENTER YOUR MESSAGE TO %s IT:\t", chx == 0 ? "ENCODE":"DECODE");
fgets(message, sizeof(message), stdin);
printf("%s", message);
return 0;
}
arubu@CQ56-LinuxMachine:master$ ./a.out
===[0]ENCODE===
===[1]DECODE===
$> 1
ENTER YOUR MESSAGE TO DECODE IT:
arubu@CQ56-LinuxMachine:master$
gcc version 5.3.0 20151204(Ubuntu 5.3.0-3ubuntu1~14.04)