Problem
Write a program that asks the user to input a file name. The program opens that file in read mode and displays it content on the screen. Use fgets function.Solution - Code
#include<stdio.h>#include<stdlib.h>
int main ()
{
char a[10],a1[10],ch;
FILE *fp,*ft;
printf ("Enter file name : ");
gets (a);
fp = fopen (a,"r");
if (fp == NULL)
{
printf ("Not found");
exit (0);
}
while (1)
{
ch = fgetc(fp);
if ( ch == EOF )
break;
printf ("%c",ch);
}
printf ("\n");
system("pause");
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.