Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,155,928 members, 7,828,219 topics. Date: Wednesday, 15 May 2024 at 06:38 AM |
Nairaland Forum / Science/Technology / Programming / Programming (786 Views)
Programming by caroline2120(f): 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 |
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. |
(1) (Reply)
Cakephp Hosting / Help Pleas How Do I Use Database Created Via Wamp "Mysql Console" / Google Makes Image Recognition Advance
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10 |