printf("\nWhich minute to query?");
gets(query);
val = strcmp (query, out);
return 0;
I tried to use gets and it did not compile and it had a runtime error. What can I substitute to make it compile.
printf("\nWhich minute to query?");
gets(query);
val = strcmp (query, out);
return 0;
I tried to use gets and it did not compile and it had a runtime error. What can I substitute to make it compile.
Here is an example using fgets
:
char query[50];
printf("\nWhich minute to query?");
fgets(query,sizeof query,stdin);
val = strcmp (query, out);
return 0;
Another example of fgets()
, from my read_stdin_fgets_string_and_arrow_keys.c file in my eRCaGuy_hello_world repo:
printf("Press any key followed by Enter, or just Enter alone, to continue: ");
char buf[1024];
char* retval = fgets(buf, sizeof(buf), stdin);
if (retval == NULL)
{
printf("fgets() failed!\n");
}
// `buf` now contains the contents of what you typed in