I was trying to manipulate strings,so I used gets. but when I read this, i found that gets is is dangerous and should not be used. so I turn on fgets, but it seems like the program escape the fgets line??? any ideas how to solve it
code:
#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;
}
execution
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)