How to use gets () & puts () ? Give me example please.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use gets () & puts () ? Give me example please..

20th Oct 2020, 6:04 AM
SARVESH ASHOK DEVRUKHAKAR
SARVESH ASHOK DEVRUKHAKAR - avatar
4 Answers
+ 5
LibraryĀ function,Ā gets(s) reads a string from the standard input into an array pointed to by s; and,Ā puts(s) writes a string pointed to by s to the standard output. ... If reading is successful,gets() returnsĀ the pointer to the string; otherwise, itĀ returnsĀ a NULL pointer, i.e. a pointer whoseĀ valueĀ is zero. Here is an detailed example https://www.javatpoint.com/c-gets-puts
20th Oct 2020, 6:20 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
gets() was removed in C11. never use it. Note from C docs: """ TheĀ gets()Ā function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear onĀ stdin). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard.Ā fgets()Ā andĀ gets_s()Ā are the recommended replacements. Never useĀ gets(). """ ~ https://en.cppreference.com/w/c/io/gets
20th Oct 2020, 6:33 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 2
Search the net for 'gets function deprecated', I would not recommend the use of `gets` function for that function is considered "dangerous". `puts` function may still be used šŸ‘Œ
20th Oct 2020, 6:34 AM
Ipang
+ 1
check documentation of c for detailed usage
20th Oct 2020, 6:11 AM
ā€ŽĀ ā€ā€ā€ŽAnonymous Guy