Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read alphanumeric data from a file and convert it in to text

Status
Not open for further replies.

palak

IS-IT--Management
Sep 9, 2003
2
0
0
IL
read alphanumeric data from a file and convert in to text format .i just want to know how do i convert in to text format .
 
Hi,

It's hard to say just what you are looking for here, but I'll take a guess and just assume you need to read a line from a file and display it.

First, open the file in text mode for reading...
(use fread( ) for binary mode)

FILE *fp;
char line[81];

fp = fopen("filname", "r"); /*need to do some error checking*/

...Then read a line with fgets and display it.

if( fgets( line, 80, fp ) == NULL)
fprintf(stderr, "fgets error\n" );
else
fprintf(stdout, "%s", line);


You can add a while loop until the EOF and do processing on each line. fgets( ) reads in one line up to and including the newline character or up to the number of chars specified (in this case, 80) - whichever comes first.

That will give you a start.

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top