0
What is the most valid way to use fgets() in this scenario?
I want to use gets(), but it's "unstable" https://code.sololearn.com/cetKuLhU8kAF/?ref=app
3 odpowiedzi
+ 3
I dont think it's the fgets that the problem..it's :-
char *textp[50];
char text[50];
fgets(&textp, 51, ); // here here here
try..
char text[50];
fgets(text, 50, stdin);
char *textp[50]; <= this creates an array of pointers
+ 1
Normally fgets() is used with a file stream (reading from a file);-
char * fgets ( char * str, int num, FILE * stream );
...but we can change it to read from the standard input (keyboard).
Be aware though...the new line (when you hit "enter") becomes part of the string, just replace it using:-
text[strlen(text)-1] = '\0';
See Here:-
http://www.cplusplus.com/reference/cstdio/fgets/
0
what is stdin
Thank you for finally answering.
For me, it's like 00:00 and i'm stressed that this might go to the "Unanswered" section forever