-1

I need to make a c program that will receive binary and output ascii,

I made the program and it works when I input "s o m e t h i n g" in to the program arguments and then the program outputs it as ascii.

But they require me to do

$cat "file" | ./"program"

when I do this nothing happens.

How do I catch this cat?

Is it not sent to my program as arguments?

LPs
  • 16,045
  • 8
  • 30
  • 61

1 Answers1

0

The data is sent to your program's standard input.

You can read that directly from stdin.

#include <stdio.h>

int main(void) {
    char line[1000];
    int n = 0;
    while (fgets(line, sizeof line, stdin)) {
        printf("%d - %s", ++n, line); // line includes ENTER
    }
    return 0;
}
pmg
  • 106,608
  • 13
  • 126
  • 198