### ASCII to Binary Convertion

Im still messed up with the code i'm having now. I dont know whats wrong with the my code. when I used cout inorder to show to binary format like 00001001 10101100 etc it shows correctly but when im trying to save it on a file it it only save an 8 bit binary like 10001010.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` `````` int ConSys::conBi(){ //String to Binary int i=0, j, k,len, ascii,binary[9], charInt,total; char letter,bi[2000], strIn[2000]; for(i=0; i<=200; i++){ bi[i]='\0'; strIn[i]='\0'; } f.open("IO.txt",ios::in); f.getline(strIn,2000); f.close(); for(i=0; i<=2000; i++){ if(strIn[i] == '\0') break; len = strlen(strIn); for(j=0; j<=len; j++) { total = 0; letter = strIn[i]; /* store the first letter */ ascii = (int)(letter); /* put that letter into an int, so we can see its ASCII number */ while(ascii>0) /* This while loop converts the ASCII # into binary, stores it backwards into the binary array. */ { if((ascii%2)==0) { binary[total] = 0; ascii = ascii/2; total++; /* increasing by one each time will yeild the number of numbers in the array. */ } else { binary[total] = 1; ascii = ascii/2; total++; } } total--; } f.open("IO.txt",ios::out); while(total>=0) { cout<

Hope you understand my code. im freshmen student only. Please have some time to look and correct the problem.
why don't you use C++ strings over C strings

eg: string name;

Aceix.
Topic archived. No new replies allowed.