PumpkinPie
PumpkinPie

Reputation: 169

Standard Input for C program using Unix Command Line

I have the following section of code in C:

int main(int argc, char *argv[]) 
{
    char *input;
    int lines;
    int p;


    input = (char*)malloc(10);
    input = argv[0];
    for(p=0;p<10;p++)
    {
        printf("%c",input[p]);
    }

On my Unix system I make the following call:

./program_name.exe < inputfile

where inputfile is a file that contains the following: 000000010Z

The output I receive to the previous commands is:

./program_

What am I missing?

Upvotes: 1

Views: 2340

Answers (1)

zubergu
zubergu

Reputation: 3706

argv[0] holds name of program being executed. And that's the only thing you print.

What you're trying to do is to read from your file as it was stdin. But you still have to read it. Use getchar(), or any other function that reads input.

Upvotes: 1

Related Questions