![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
Shakti
You have to read that first, before posting code. That is why it's called "Posting Code? Read this First".
fgets is not like scanf, it doesn't take the format of the input as an argument.
(fgets - C++ Reference)
Code:
char * fgets ( char * str, int num, FILE * stream );
str
Pointer to an array of chars where the string read is stored.
num
Maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.
stream
Pointer to a FILE object that identifies the stream where characters are read from.
To read from the standard input, stdin can be used for this parameter.
This is the function declaration of fgets, it tells you what you have to give to the function and what it gives to you.
The first thing to supply to fgets is the string where the input is stored. This is the same as the second argument that you usually supply to scanf (well, mostly).
num is how many characters you want to read, as the documentation says just set it to the length of your respective arrays. This is to ensure that the function does not read more than you can store.
the third argument is a little more complicated for beginners, and may not be worth explaining to you in your first program. most simply, you want to read from the keyboard, so provide 'stdin' (without the inverted commas) as this argument.
On another note, statements in C end with a semicolon. return is a C statement.
I refuse to believe that your compiler is not giving you error messages, please post them and try to interpret them.