ASCII to letters program

ASCII to letters program

Post by IncandescentLight on Wed Nov 18, 2009 6:41 am
([msg=30547]see ASCII to letters program[/msg])

I have written the program with the following code, and it changes ASCII to letters but what I want it to do is convert the ASCII to ABC and vice versa by words, not individual letters, but I don't know how to do it. I understand that converting ASCII words to ABC might be a problem as the numbers are all messed up, some two digits and three, so I want to have a '|' placed between each number. I also want the ABC to ASCII function be able to accept the input in this way. Any ideas? Help much appreciated :D

(Written in C++, and variables might be messed up a bit)
Code: Select all
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main()

        int number;
        char letter;
        char word;
        int x = 0;
        int option;
int num;
int lag = 10;
string s;
int a;
int key;

while (lag>9)
        cout<<"Convert ASCII numbers into characters and vice versa";
        cout<<endl<<"[1] * ASCII -> ABC"
                <<endl<<"[2] * ABC -> ASCII"
                <<endl<<"[3] * EXIT"<<endl;;
cout<<"Option :";

        switch (option)
                case 1:
                        cout<<"Enter a letter : ";
                        cin >> letter; //Inputs the number
                        cout<<"Enter the shift key: ";
                        cin >> key; //Gets the key
                        cout<<"The number you entered is : \""<<char(number) + key<<"\" in ASCII"<<endl; //Ouputs the same number in char

                case 2:
cout << "Please enter the letter";
cin >> word;
cout << "The ASCII for this word is:";
cout << int(word);
cout << " \n";


                case 3:
                     return 0;

                        cout<<"Invalid Option!";
        return 0;
Speak softly and carry a big stick -Theodore Roosevelt
User avatar
Posts: 216
Joined: Sun Apr 27, 2008 3:16 am
Blog: View Blog (0)

Re: ASCII to letters program

Post by faazshift on Sat Nov 21, 2009 3:20 am
([msg=30620]see Re: ASCII to letters program[/msg])

To accomplish this I would suggest making a specialized function for converting ascii to '|' separated decimal, and a second function to reverse it. Then in the main function determine if it is encoded or not (by checking if the input consists of more that just numbers, spaces, and '|'), and based on that split by space characters and run the needed function on each word. Then you can concatenate the output words, separating them by spaces, and magic, it works. I hope this explains what you need to do to accomplish what you are trying to.
Posts: 516
Joined: Wed Jun 03, 2009 3:55 pm
Location: Riverton, Utah
Blog: View Blog (0)

Re: ASCII to letters program

Post by OnlyHuman on Sat Nov 21, 2009 5:38 am
([msg=30621]see Re: ASCII to letters program[/msg])

I had to read this a second time to make sure I got it. I was having a little trouble reading your code. What you're trying to accomplish is going to require using more than just a character for input. Try the std::string or std::stringstream object.
Posts: 192
Joined: Sat Aug 22, 2009 1:37 am
Blog: View Blog (0)

Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests