Programming - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Programming (850 Views)
| Programming by caroline2120(op): 4:49pm On May 23, 2013 |
please i want to convert string to ascii code and vice versa. e.g "ade" to ascii code and back to "ade" |
| Re: Programming by simplyme3(f): 7:29pm On May 23, 2013 |
#include <iostream.h> int main() { char word[32]; int x = 0; [B]int ascii[32];[/B] cout << "Please enter the word (maximum 32 characters):\n"; cin >> word; cout << "The ASCII for this word is:\n"; while (word[x] != '\0') // While the string isn't at the end... { [B]ascii[x] = int(word[x]); // Transform the char to int[/B] x++; } [B] //Now, to display the array with the asciis... for (x=0; x<32; x++) { cout << ascii[x] << ' '; }[/B] cout << "\n"; return 0; } |
| Re: Programming by WhiZTiM(m): 1:48am On May 24, 2013*. Modified: 12:14pm On May 24, 2013 |
simply_me: #include <iostream.h>good one... But err. . . Madam, printing an array of 32 ints when the user's input only initializes less than 32 of them will print garbaged or max int. Your code is a C styled code in C++... I discourage that. Why don't you use the string class... Feed the string, then use the string.size() to instantiate the array ...convert to ascii like you did ...and loop over the int array using the string.size() as boundary ? ? ...its much cleaver that way. ![]() ...btw, I feel humbled whenever I see a ....ehhmm... What was I saying again? ? .. ![]() |
| Re: Programming by petersmith5544(m): 1:47pm On May 25, 2013 |
Programming is instructing a computer to do something for you with the help of a programming language. The role of a programming language can be described in two ways: Technical: It is a means for instructing a Computer to perform Tasks Conceptual: It is a framework within which we organize our ideas about things and processes. |
How To Learn Asp.net • How To Programme A PBX • Computer Science Project
