I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

text file reading

sumith\′s Photo
28 Nov 06, 7:16AM
(1 reply)
text file reading
hi

how to read a line and an item from a text file using C program please help

nicholdug\′s Photo
1 Dec 06, 6:46AM
Dear Sumith,

To read a line form a file using C programing language you can use fgetc(). Which gets character from a file. Here is an example. Pls. feel free if u need. I have used Turbo 3.0.

#include<stdio.h> #include<conio.h>

void main() { FILE *myfile; char ch;

myfile=fopen("sample.txt","r"); //The file you want to read is "sample.txt".

while(1) {

ch=fgetc(myfile);

if(ch==EOF) break;

printf("%c", ch); }

getch(); }

//you can manipulate the character which is collected in ch. You can display it on standard console or in some other file.

//Hope you got your answer.

Currently you need to be logged in to leave a message.