This function "gets" reads a whole line of input from standard input (stdin) into a string until a newline or EOF (End-of-File) is encountered. It is critical to ensure that the string is large enough to hold any expected input lines.
Syntax of gets function
char * gets ( char * str );
This function takes one parameter i.e. a string or character pointer (char * str) as input and stores the line taken as input from stdin in the same string i.e. in the variable str.
Example using gets funtion
#include <stdio.h> int main() { char address [256]; printf ("Insert your full address: "); gets (address); printf ("Your address is: %s\n",address); return 0; }
Return Value
In case,
- When end-of-file is encountered, a pointer is returned which points to the string that is just inputted.
- If no characters are read or some error occurs during reading characters, a null pointer is returned.
Your example here is not correct.
Hope it didn't frustrate too many students learning C looking for guidance.
Anyway please review it again and fix it.
Thanks Fuser. The example has been corrected.
Sorry for the inconvenience.
Hi Buddie,
Your writing shines! There is no room for gibberish here clearly you have explained about What is gets Function in C with Syntax and Example . Keep writing!
Write a LEX program (i know this is in C) that identifies words from the previous set of phrases, such that an input of the form "triangle BCD" returns:
---Triangle: a geometric entity (lol at that)
---BCD: name of a geometric entity
b) Define the tokens, lexemes and patterns to be found in formal expressions concerning these three sentences.
c) Construct the finite automaton that corresponds to the formal expressios to describe the names of geometric entities in that language. Use this to see if the name AYZ is recognizable.
But nice Article Mate! Great Information! Keep up the good work!
Cheers,
Irene Hynes