For one hand, in this question, I tried to compile the code. But what I was really trying was to get the string from console and then work with it.
This is a really old DOS problem. Anyway, if you run this code:
int main() {
FILE *f, *file;
file = fopen("resultado.txt","w");
for (unsigned int i=0; i<256; i++) {
char result[60];
snprintf(result, 12, "echo %c %i", (char)i, i);
f = popen(result, "r");
char linha[512];
while (fgets(linha, 512, f)) {
fprintf(file, "%c %i --> C ", (char)i, (int)i);
fprintf(file, "%s", linha);
}
}
fclose(file);
return 0;
}
It will print in the text all ASCII code and how the console see it. From 0 to 127 it is equal. After it, you need to change. This is Code Page 850
and I don't see an easy way to do it, but I did it myself.
Getting all printable character, I have this array:
const unsigned int translate[] = {199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,131,225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187,0,0,0,0,0,193,194,192,169,0,0,0,0,162,165,0,0,0,0,0,0,0,227,195,0,0,0,0,0,0,0,164,240,208,202,203,200,0,205,206,207,0,0,0,0,166,204,0,211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180,173,177,0,190,182,167,247,184,176,168,183,185,179,178,0};
Now loop all string you get and use
for (int i= 0; i< size; i++) {
unsigned char mychar = (unsigned char)text[i];
if (mychar>= 128){
mychar =translate[mychar - 128];
}
text[i] = mychar
}
And now you can work with the string in normal ASCII in C program.