Looking up some documentation for fgets,
Declaration
char *fgets(char *str, int n, FILE *stream)
Parameters
- str − This is the pointer to an array of chars where the string read is stored.
- n − This is the maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.
- stream − This is the pointer to a FILE object that identifies the stream where characters are read from.
So the difference is that we need to supply the stream (in this case, stdin aka input) and the length of the string to be read from stdin.
The following should work:
#include <stdio.h>
#define BUFLEN 7
int main(int argc, char **argv) {
char buf[BUFLEN]; // buffer for seven characters
fgets(buf, BUFLEN, stdin); // read from stdio
printf("%s\n", buf); // print out data stored in buf
return 0; // 0 as return value
}