Tuesday, February 10, 2015

Reading A File

/* 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; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar