Skip to content
← Back to Community
When I try to use the gest() function in C. I always get a warning "gets is invalid in C99"
Profile icon
Alexander1231

When I try to use the gets() function in C. I always get a warning "gets is invalid in C99"

Does anyone know why this is happening? Also how to fix the problem so I can use the function without any warnings?

The function works in this code but in other codes it doesn't work correctly

Voters
Profile icon
MattoMoriconi
Profile icon
AashiqAhmed
Profile icon
xCatta
Profile icon
Alexander1231
Comments
hotnewtop
Profile icon
mwilki7

from what I'm getting from
https://stackoverflow.com/questions/49256131/why-is-implicit-declaration-of-gets-not-allowed-in-c99
gets was removed from the standard library and this error message was a notification for those with this in their legacy code to remove it

so it depends how old the compiler you're using is

you should use fscanf(file pointer, format string, argument1, argument2...) as a substitute

Example:

#include <stdio.h> int main() { int test_input = 0; printf("Test input: "); fscanf(stdin, "%d", &test_input); printf("Test output: %d", test_input); return 0; }

Output:

Test input: 2 Test output: 2
Profile icon
AashiqAhmed

use string.h

Profile icon
NathanWickenden

@AashiqAhmed
You still get the problem, it has nothing to do with the string.h library in c