I need to do something like the following:
int main(void) {
char a,b,cstring;
printf(\"please enter something\");
scanf(\"%c %c\",&a,&b);
prinf(\"th
The problem is when the flow reaches fgets(), this API first looks at stdin for input and it finds a stray '\n' there. As for fgets() which said that this API returns when it encounters EOF or '\n', since fgets() got '\n' from stdin so it executed without waiting for user to enter something as the APIs returning conditions met.
Solution to the problem is that you use getchar(); after scanf and ignore the extra characters left by scanf(). e.g:
scanf("%lf",&e);
getchar();
fgets(t,200,stdin);
or
other solution can be to use sscanf with fgets. e.g:
#include
int main() {
int j;char t[200];
fgets(t,200,stdin);
sscanf(t,"%d",&j);
}