You just open stdin as file but you don't read your file.
There are many different ways to get input from stdin.
Function getchar
can be used to read a single character from stdin. Use getc()
or fgetc()
to read from an arbitrary file stream.
Example:
int c = getchar();
printf("you entered %c\n", c);
Function fgets
can be used to read a line from file.
Example:
char data[200];
fgets(data, sizeof(data), stdin); // we type stdin as file.
printf("you entered %s\n", data);
Function scanf
and its family of functions can be used to read many different formats from stdin.
example:
char data[200]; // size need be bigger or equal to input length
scanf("%199s", data); // Protect from buffer overflow
printf("you entered %s\n", data);