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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regarding files in C

Status
Not open for further replies.

sendman123

Programmer
May 12, 2006
1
US
Hi,

I have a C program that reads the data from a file called "info" and prints it. Here is the code.

#include <stdio.h>

void main()
{
FILE *fopen(), *fp;
int c ;

fp = fopen("info","r");
c = getc( fp ) ;
while ( c != EOF )
{ putchar(c);
c = getc ( fp );
}

fclose( fp );

}

Now the data in the info file is:

nbsol148
ADM-16
TP2.1
NULL

I get the output in the same manner. I want the output in a single line. Is it possible. If yes, how to do it.

Thanks in advance
 
Check for line feed and carriage return and replace with space.
while ( c != EOF )
{ if ((c == 0x0a) || (c == 0x0d)) c=' ';
putchar(c);
c = getc ( fp );
}
 
You're reading char by char, so you can check if the received char is a line break, and just write a space instead.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top