简体   繁体   中英

Executing a File Copying program written in C in terminal

This is the code:

#include<stdio.h>

main(){
        int c;
        c = getchar();
        while( c != EOF ){
                putchar(c);
        }
}

I have made another file named "AFile" using vim.

To display the contents of "AFile" using my program, what command do I write in the terminal?

Your program reads from STDIN (fd 0), so you need to provide data at via stdin. In most shells, this can be done with the redirect operator < :

./yourprogram < inputfile

Another way would be using a pipe, but it is generally not recommended, because it needs to start an unnecessary second process:

cat inputfile | ./yourprogram

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM