'How can I get arguments from standard input in C? [duplicate]
I have a string that I want to execute in C file and I'd like to get the string from standard input.
echo "Here is some random text.\n" | ./main.c
Solution 1:[1]
Read from stdin
like any other FILE
stream.
#include<stdio.h>
int main()
{
char line[BUFSIZ];
fgets(line, sizeof(line), stdin);
printf("stdin: %s", line);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Schwern |