Thursday, September 11, 2014

display c source file on the console using fgetc function


Problem

Write a C program to open any C source file and displays its content on console. Use fgetc function.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
 FILE *fp;
 char ch;

 fp = fopen ("p2.txt","r");

 while (1)
 {
  ch = fgetc(fp);
  if ( ch == EOF )
   break;

  printf ("%c",ch);
 }

 fclose (fp);
 system ("pause");
 return 0;
}

Sample Output

display source file using fgetc function

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact