Basically, I’m trying to implement the following:
echo "asdf" | ./a.out
where ./a.out simply prints out “asdf”
I know this is probably noob C stuff, but as I’m only a novice C programmer, I thought I’d ask the community.
Update:
OK, I got it:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[80];
int i;
printf("Enter a string: ");
fgets(str, 10, stdin);
/* remove newline, if present */
i = strlen(str)-1;
if( str[ i ] == '\n')
str[i] = '\0';
printf("This is your string: %s", str);
return 0;
}
echo "asdf" | ./a.out does what I need.
It is coming through
stdin.