0

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

1 Answers1

0

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);
}
Schwern
  • 139,746
  • 23
  • 170
  • 313