Sorry for this terrible of a question.
I've looked everywhere for an answer, and nothing seems to work!!!
I'm trying to make file sending. So what happens is, I could send a file with words and such. But when sending a .exe or .bmp or anything with random letters in it, it stops after the first space.
So I'm going to convert text to binary on the server, send to the client, then the client converts binary to ASCII and outputs it into a file.
I can easily send the binary code, and that's all complete. But my current problem is how do I convert the binary code to ASCII???
Here's what I'm doing right now:
Code: Select all
//fullFile2 is the received binary file!
std::string fullFile = "";
for (int i = 0; i < fullFile2.length()/8; i++) {
char c = strtol((char*)fullFile2.substr(i*8,i*8+8).c_str(), 0, 2);
std::cout << fullFile2.substr(i*8,i*8+8) << std::endl; //Outputs correct binary code!
std::cout << c << std::endl; //Outputs INCORRECT letters! First two letters correct, rest are wrong
fullFile += c;
}
std::ofstream myFile;
myFile.open("Test.bmp");
myFile << fullFile;
myFile.close();
But char c = strtol((char*)fullFile2.substr(i*8,i*8+8).c_str(), 0, 2);
is returning mostly incorrect characters.
Anything I'm doing wrong here?? Please help!
Thanks!
Researched Links:
http://stackoverflow.com/questions/1082 ... -char-in-c
http://www.dreamincode.net/forums/topic ... y-to-char/
http://www.cplusplus.com/forum/general/1764/
etc..