delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/26/15:54:48

From: "usha1" <usha1 AT optushome DOT com DOT au>
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: <TZ_h7.4880$Ee.32352@news1.rdc1.nsw.optushome.com.au>
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 <string>
#include <iostream>
#include <cctype>
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;
}







- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019