What is the most valid way to use fgets() in this scenario? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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

29th Nov 2020, 9:05 PM
OverdrivedProgrammer
3 Réponses
+ 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
29th Nov 2020, 9:46 PM
rodwynnejones
rodwynnejones - avatar
+ 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/
29th Nov 2020, 10:41 PM
rodwynnejones
rodwynnejones - avatar
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
29th Nov 2020, 9:50 PM
OverdrivedProgrammer