gets() and puts() console input output (I/O) functions in C

gets(): When we enter characters from the keyboard gets()function reads these characters. Then these characters are placed at an address pointed by its argument. All the characters pressed are read until enter is hit. Carriage return doesn’t happen in gets(). While typing if there’s a typo it can be fixed by backspace. Disadvantage of gets() is that there is no boundary checking done for the array receiving input. So, sometimes users tend to enter more characters than the array can hold. Hence, it is avoided in commercial coding.

Syntax of gets():

char *gets(char *str);

puts (): puts(0 is used for writing a string to a screen followed by a new line. puts() can only output strings, it cannot output numbers and cannot do format conversions. It is used for writing a highly optimized code.

Syntax of puts():

int puts(const char *str);

Leave a Reply