On Jul 24, 3:41 am, Nick Keighley <nick_keighley_ nos...@hotmail. com>
wrote:
please include the subject in the body of your text
Subject: convert binary file to txt file
On 23 Jul, 17:46, xiao <littledd...@gm ail.comwrote:
On Jul 23, 11:20 am, CBFalconer <cbfalco...@yah oo.comwrote:
xiao wrote:
Can I fullfill this task? Using fred and fwrite?
what format is the binary file? What do you want the text to look
like.
For instance the binary could be an executable and the text file
might be a hex dump or the binary might be a word processor
document and the text an ASCII dump of the text of the document.
The possibilities are endless. But the answer is yes in princple.
If you can find fred.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
don't quote sigs (the bit after --)
haha, I made a mistake here, I mean fread....but it seems fread does
not working....
fread() will almost certainly work on any reasonable
implementation. Please post your code and explain
why you think fread() is "not working".
--
Nick Keighley
A man's most valuable trait is a judicious sense of
what not to believe.
-- Euripides
Thank you guys~ I modified the program like the below but the new
generated txt file is a little less then the original dat file. Is
that reasonalble? I think it is not right Thank you ~~~
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct
{
double CentLat;
double CentLon;
double DeltaX;
double DeltaY;
long ProjectionID;
double ProjectionParam eters1;
double ProjectionParam eters2;
double ProjectionParam eters3;
double ProjectionParam eters4;
double ProjectionParam eters5;
double ProjectionParam eters6;
double ProjectionParam eters7;
double ProjectionParam eters8;
double ProjectionParam eters9;
double ProjectionParam eters10;
double ProjectionParam eters11;
double ProjectionParam eters12;
double ProjectionParam eters13;
double ProjectionParam eters14;
double ProjectionParam eters15;
long MapZone;
int NumX;
int NumY;
// The number of rays in
} NSC_RAY_DATA_HE ADER;
/* Define the data structure for the ray information */
int main( )
{
double CentLat1;
double CentLon1;
double DeltaX1;
double DeltaY1;
long ProjectionID1;
double ProjectionParam eters11;
double ProjectionParam eters12;
double ProjectionParam eters13;
double ProjectionParam eters14;
double ProjectionParam eters15;
double ProjectionParam eters16;
double ProjectionParam eters17;
double ProjectionParam eters18;
double ProjectionParam eters19;
double ProjectionParam eters110;
double ProjectionParam eters111;
double ProjectionParam eters112;
double ProjectionParam eters113;
double ProjectionParam eters114;
double ProjectionParam eters115;
long MapZone1;
int NumX1;
int NumY1;
int rc = EXIT_FAILURE;
FILE *in, *out;
NSC_RAY_DATA_HE ADER nscrdh;
/* Determine the file names to be read from and written to */
/* Open the files to be read from and written to*/
in = fopen("CldTotal Stats_8.dat","r b");
out = fopen("newstats .txt","w");
if ( in != NULL )
{ printf ("Opened the file successfully\n" );}
/* Read necessary header data into local variables & confirm file
format */
fread(&nscrdh,s izeof(nscrdh),1 ,in);
CentLat1=nscrdh .CentLat;
CentLon1=nscrdh .CentLon;
DeltaX1=nscrdh. DeltaX;
DeltaY1=nscrdh. DeltaY;
ProjectionID1=n scrdh.Projectio nID;
ProjectionParam eters11= nscrdh.Projecti onParameters1;
ProjectionParam eters12= nscrdh.Projecti onParameters2;
ProjectionParam eters13= nscrdh.Projecti onParameters3;
ProjectionParam eters14= nscrdh.Projecti onParameters4;
ProjectionParam eters15= nscrdh.Projecti onParameters5;
ProjectionParam eters16= nscrdh.Projecti onParameters6;
ProjectionParam eters17= nscrdh.Projecti onParameters7;
ProjectionParam eters18= nscrdh.Projecti onParameters8;
ProjectionParam eters19= nscrdh.Projecti onParameters9;
ProjectionParam eters110= nscrdh.Projecti onParameters10;
ProjectionParam eters111= nscrdh.Projecti onParameters11;
ProjectionParam eters112= nscrdh.Projecti onParameters12;
ProjectionParam eters113= nscrdh.Projecti onParameters13;
ProjectionParam eters114= nscrdh.Projecti onParameters14;
ProjectionParam eters115= nscrdh.Projecti onParameters15;
MapZone1=nscrdh .MapZone;
NumX1=nscrdh.Nu mX;
NumY1=nscrdh.Nu mY;
fprintf(out, "%lf %lf %lf %lf %ld %ld %d %d",CentLat1,
CentLon1,DeltaX 1, DeltaY1,Project ionID1,MapZone1 ,NumX1,NumY1);
/* for(i=0; i<14 ;i++){
fprintf(out,"%l d",ProjectionID 1[i]);
}*/
fprintf(out,"%l d",ProjectionID 1);
/* Write header, ray information into output file */
printf("The center latitude and cent longtitute are %lf %lf
\n",CentLat1,Ce ntLon1);
printf("The deltax and deltay are %lf %lf \n",DeltaX1, DeltaY1);
printf("The projection ID is %ld \n",ProjectionI D1);
printf("The MapZone is %ld \n",MapZone1) ;
printf("The projection parameter are %lf
\n",ProjectionP arameters11);
printf("The projection parameter are %lf
\n",ProjectionP arameters12);
printf("The projection parameter are %lf
\n",ProjectionP arameters13);
printf("The projection parameter are %lf \n",ProjectionP arameters14);
printf("The projection parameter are %lf \n",ProjectionP arameters15);
printf("The projection parameter are %lf \n",ProjectionP arameters16);
printf("The projection parameter are %lf \n",ProjectionP arameters17);
printf("The projection parameter are %lf \n",ProjectionP arameters18);
printf("The projection parameter are %lf \n",ProjectionP arameters19);
printf("The projection parameter are %lf
\n",ProjectionP arameters110);
printf("The projection parameter are %lf
\n",ProjectionP arameters111);
printf("The projection parameter are %lf
\n",ProjectionP arameters112);
printf("The projection parameter are %lf
\n",ProjectionP arameters113);
printf("The projection parameter are %lf
\n",ProjectionP arameters114);
printf("The projection parameter are %lf
\n",ProjectionP arameters115);
printf("The numy and numx are %d %d \n",NumX1,NumY1 );
/* fread(&nscrd,si zeof(nscrd),14, in);
xx= nscrd.x;
for(a=0; a<800 ;a++){
for(b=0; b<800 ;b++){
xx[a][b]=nscrd.x[a][b];
}
}
fprintf(out,"%h d", xx);
printf("The numbers are %d \n",xx);
}*/
/* Close files and exit the program */
if(out != NULL)
{
short sh = 0;
while(fread(&sh , sizeof( sh), 1, in) 0)
{
fprintf(out, "%hd", sh);
}
printf("The itams read in the file are %d\n",fread(&sh ,
sizeof( sh),1,in));
if(!ferror(in) && !ferror(out))
{
rc = EXIT_SUCCESS;
}
fclose(out);
}
fclose(in);
return rc;
}