+ 3

Is scanf () function automatically allocate space for null terminator like fgets()? In C

|| Otherwise we have to manually allocate a space for null terminator in scanf() while handling with strings....? https://code.sololearn.com/cC9K438PtS1C/?ref=app

14th Oct 2020, 6:24 AM
Yogeshwaran P
Yogeshwaran P - avatar
1 Réponse
+ 5
Neither scanf() nor fgets() allocate space for input strings and NULL terminators. The caller must provide pre-allocated memory space for string input, and yes, be certain to have a spare byte to accept the terminating NULL when calling either function.
14th Oct 2020, 6:47 AM
Brian
Brian - avatar