I tried this code and the wrote another similar one to read another input but the program read in the second time both the first stdin and the second one (also I used fflush(stdin) instead of fseek() but that didn't work either)
int BUFFERSIZE=100;
char input[BUFFERSIZE];
char *final=malloc(1);
while(fgets(input,BUFFERSIZE-1,stdin))
{
final=realloc(final,strlen(final)+strlen(input)+1);
strcat(final,input);
if(input[strlen(input)-1]=='\n') break;
}
sscanf(final,"%d",&opt);
free(final);
fseek(stdin,0,SEEK_END);
-1
not needed infgets(input,BUFFERSIZE-1,stdin)
. Suggestfgets(input, sizeof input, stdin)
. – chux - Reinstate Monica