Click here to Skip to main content
15,907,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionConvert a binary file to an ASCII file Pin
NYTSX22-Mar-06 13:23
NYTSX22-Mar-06 13:23 
AnswerRe: Convert a binary file to an ASCII file Pin
kakan22-Mar-06 19:53
professionalkakan22-Mar-06 19:53 
GeneralRe: Convert a binary file to an ASCII file Pin
Eytukan22-Mar-06 20:44
Eytukan22-Mar-06 20:44 
GeneralRe: Convert a binary file to an ASCII file Pin
kakan22-Mar-06 20:52
professionalkakan22-Mar-06 20:52 
GeneralRe: Convert a binary file to an ASCII file Pin
NYTSX23-Mar-06 0:49
NYTSX23-Mar-06 0:49 
GeneralRe: Convert a binary file to an ASCII file Pin
kakan23-Mar-06 1:09
professionalkakan23-Mar-06 1:09 
GeneralRe: Convert a binary file to an ASCII file Pin
NYTSX23-Mar-06 1:39
NYTSX23-Mar-06 1:39 
GeneralRe: Convert a binary file to an ASCII file Pin
kakan23-Mar-06 2:04
professionalkakan23-Mar-06 2:04 
OK, this has to be quick, since I'm at work...
There are other, maybe better ways to do this...

<code>
#include <stdio.h>
#include <string.h>

FILE *in;
FILE *out;
char * infileName = "infile";
char * outfileName = "outfile";
unsigned char buf[10];

if((in = fopen(infileName, "rb")) == NULL) {
printf("Nope. The infile %s doesn't exist!\n",infileName);
return 1;
}

if((ut = fopen(outfileName, "wb")) == NULL) {
printf("Nope. Can't create the out file %s!\n",outfileName);
fclose(in);
return 1;
}

// Process
while(fread((char *) buf,1,1,in) != 0) {
if(buf[0] >= (unsigned char) ' ') fwrite(buf,1,1,ut);
else {
// Values below space
if(buf[0] == (unsigned char) '\r' || buf[0] == (unsigned char) '\n') fwrite(buf,1,1,ut);
else fprintf(ut, "\x%02X", (unsigned int) buf[0]);
}
}
fclose(in);
fclose(ut);
return 0; // OK
</code>

This is written in a hurry, and partially untested. But it should work.
If you wan't to ommit "the low values", simply comment out the line
else fprintf(ut, "\x%02X", (int) buf[0]);

Good luck.



-- modified at 8:19 Thursday 23rd March, 2006
GeneralRe: Convert a binary file to an ASCII file Pin
NYTSX23-Mar-06 2:32
NYTSX23-Mar-06 2:32 
Questionmemory usage keeps going up when retrieving webcam image Pin
khrstopher22-Mar-06 13:21
khrstopher22-Mar-06 13:21 
AnswerRe: memory usage keeps going up when retrieving webcam image Pin
MF22-Mar-06 15:48
MF22-Mar-06 15:48 
GeneralRe: memory usage keeps going up when retrieving webcam image Pin
Stephen Hewitt23-Mar-06 12:17
Stephen Hewitt23-Mar-06 12:17 
Questiondataset / datagrid in visual C++ 6 Pin
viperlogic22-Mar-06 12:20
viperlogic22-Mar-06 12:20 
AnswerRe: dataset / datagrid in visual C++ 6 Pin
Christian Graus22-Mar-06 13:45
protectorChristian Graus22-Mar-06 13:45 
AnswerRe: dataset / datagrid in visual C++ 6 Pin
Eytukan22-Mar-06 20:48
Eytukan22-Mar-06 20:48 
JokeRe: dataset / datagrid in visual C++ 6 Pin
toxcct22-Mar-06 21:18
toxcct22-Mar-06 21:18 
AnswerRe: dataset / datagrid in visual C++ 6 Pin
toxcct22-Mar-06 22:52
toxcct22-Mar-06 22:52 
GeneralRe: dataset / datagrid in visual C++ 6 Pin
viperlogic23-Mar-06 0:17
viperlogic23-Mar-06 0:17 
GeneralRe: dataset / datagrid in visual C++ 6 Pin
toxcct23-Mar-06 1:51
toxcct23-Mar-06 1:51 
QuestionSetThreadLocale Pin
SanShou22-Mar-06 12:04
SanShou22-Mar-06 12:04 
AnswerRe: SetThreadLocale Pin
MF22-Mar-06 15:59
MF22-Mar-06 15:59 
Questiondisplaying pictures Pin
Amr Shahin22-Mar-06 11:25
Amr Shahin22-Mar-06 11:25 
AnswerRe: displaying pictures Pin
Christian Graus22-Mar-06 11:41
protectorChristian Graus22-Mar-06 11:41 
GeneralRe: displaying pictures Pin
Waldermort22-Mar-06 13:54
Waldermort22-Mar-06 13:54 
AnswerRe: displaying pictures Pin
Hamid_RT22-Mar-06 17:39
Hamid_RT22-Mar-06 17:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.