Day 1 1-1 Tuesday 2019-01-15

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 

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
>

你可能感兴趣的:(Day 1 1-1 Tuesday 2019-01-15)