From: "usha1" Newsgroups: comp.os.msdos.djgpp Subject: Text Encoder Program HELP Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: Date: Sun, 26 Aug 2001 04:32:51 GMT NNTP-Posting-Host: 203.164.186.200 X-Complaints-To: abuse AT optushome DOT com DOT au X-Trace: news1.rdc1.nsw.optushome.com.au 998800371 203.164.186.200 (Sun, 26 Aug 2001 14:32:51 EST) NNTP-Posting-Date: Sun, 26 Aug 2001 14:32:51 EST Organization: @Home Network To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com i cant get c++ to do two things... the first instead of encoding when the user preses f, i need it to encode once the user presses "control z" or "F6" second thing is i dont know how to keep the new lines made... eg say i put line one: hello line two: how are you my prog just encodes it into the one line :(...please if you can help me, i will be much appreciated.. here is my semi final code.. //File: s3069242.cpp //Encodes a Message #include #include #include using namespace std; int main() { const string ALPHABET= "abcdefghijklmnopqrstuvwxyz0123456789"; const string CODE= "fghijklmnopqrstuvwxyzabcde1234567890"; string message; //message to encode char ch; //next message character int pos; //its position cout << "Enter a string to encode : "; getline(cin, message, 'f'); // Encode message. for (int x = 0; x < message.length(); x++) { ch = tolower(message.at(x)); //ch to lowercase pos = ALPHABET.find(ch); //find position of ch if ((pos >= 0) && (pos < 36)) message[x] = CODE.at(pos); else message[x]=' '; } for (int y = 0; y < message.length(); y++) { if (message[y]==' ') { message[y]=message[y+1]; message[y+1]=' '; y++; } } cout << "The Encoded Message is : " << message << endl; return 0; }