Programming / Computing

Print the file content

 This program will print all the content of the file whose name is given in the place of 

FILENAME.TXT 

ex:        abc.txt

 

 

 

#include<stdio.h>

#include<process.h>

#include<conio.h>

 // Point out error , if no error then write output

void main()

{

int l,o;

char c;

FILE *fp;

fp = fopen("FILENAME.TXT","r");

clrscr();

if(fp == NULL)

{

printf("the file do not exist");

exit(1);

}

l = 1;

o = 0;

while(1)

{

if(o==0)

 printf("%d",l);

o=1;

 

c = getc(fp);

if( c == EOF)

break;

 

printf("%c",c);

if( c == '\n')

{

o=0;

l++;

}

}

getch();

}

 

© 2010 All rights reserved.

Make a free websiteWebnode