cs20207
gather user's first name and last name from a file as a command line argument and print it to the console.
hi.c
#include <stdio.h>
int main(int argc, char *argv[]) {
int c;
FILE *fp = fopen(argv[1], "r");
if (fp) {
printf("Hello world, I am ");
while((c = getc(fp)) != EOF) putchar(c);
fclose(fp);
}
return 0;
}
name.txt
Beixi Hao
> gcc -o hi hi.txt
> ./hi "name.txt"
Hello world, I am Beixi Hao
>
网友评论