Hello all,
I need your help. I need a very quick program on taking in a file filled with characters and writing into a file with each character's ASCII (hex representation). This is a very dirty code but it does work. The problem I am having is how to write into a new file. Please help. Thank you.
Code:// This program takes a sample C++ file and encrypts // it with the ASCII hex representation #include <iostream> #include <string> using namespace std; string lookup_hex(char blurb); int main(){ // creates a file pointer FILE * thisFile; // file object to read from FILE * thatFile; // file object to write from // opens file thisFile = fopen("test.txt", "r"); thatFile = fopen("output.txt", "w"); // initializes the character char c; while (thisFile != NULL){ // takes in a character c = fgetc(thisFile); // evaluates character string hex_value = lookup_hex(c); // writes ANSI characters in new file fwrite(, thatFile); } return 0; } string lookup_hex(char blurb){ char test[2]; switch(blurb){ case ' ': test[0] = '2'; test[1] = '0'; break; case '!': test[0] = '2'; test[1] = '1'; break; case '"': test[0] = '2'; test[1] = '2'; break; case '#': test[0] = '2'; test[1] = '3'; break; }; return test; }



LinkBack URL
About LinkBacks


