Due: Friday, November 3, 2017, 11:00 am (Session A) 1:00 pm (Session B) (start of the class)

The following C code tries to read a filename from standard in and print the file to the standard out.

/**
 * Get a filename from standard in, read the file, and print it to standard out
 */

#include<stdio.h>
#include<stdlib.h>

int main() {
	int c;
	FILE *fp;
	char fname[50];
	
	printf("Enter the name of the file: ");
	scanf("%s", fname);
	fp = fopen(fname, "r");
	
	while ((c = getc(fp)) != EOF) 
		putchar(c);
	
	return 0; 
}

List out the problems in the code.

© 2017 Ying Li. Page last modified: .