/* Write a program in C to read the contents of a file */
#include <stdio.h>
int main() {
    char fname[20];
    printf("Enter the name of the file to read: ");
    scanf("%s", fname);
    char str[70];
    FILE *p;
    if((p=fopen(fname,"r"))==NULL){
        printf("\nUnable to open file %s", fname);
        exit(1);
    }
    while(fgets(str, 70, p) != NULL)
        puts(str);
    fclose(p);
    getch();
    return 0;
}
Tuesday, February 10, 2015
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment