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

From binary to text

Status
Not open for further replies.

DerPflug

Programmer
Mar 28, 2002
153
US
Is it possible to read a binary file and write it to a text file? For instance, specify source and destination file names, read the source binary file, and write it as a text report to another file? All of this without displaying it on the screen. Thanks.
 
Not exactly sure what do you want to do. But it is possible to open a file in one format and write it in another format. However, there are a few notes

1. A text file only consist of a subset of all possible binary characters - all lower printable ASCII and some control characters.

2. Open the file in text mode causes the read/write operation to perform 'translation' when reading/writing the file. And the kind of translations are system dependent.

HTH
Shyan
 
I solved it this way:

do //read the file and print it
{
{
if(fread(&partrecord, sizeof(part), 1, source) < 1)
{
if(feof(source) != 0)
{
fclose(source);
break;
}
perror(&quot;fread&quot;);
printf(&quot;\t\tThere was an error reading
the file.\n&quot;);
fclose(source);
break;
}
fprintf(destination, &quot;%s&quot;, partrecord);
}while(1);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top