473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

wrap around alphabet??

hello, i'm working on a decoder program that lets the user input a key
(integer between 0 and 26) and then subtracts that number from a given
letter to produce a decoded message. for example, 'Y' - 12 = 'M'. My
problem is I would like the program to "wrap around the alphabet" when
it subtracts the key from the original letter. Ex. 'B' - 5 = 'W'.
this must work for lower and uppercase letters. any help would be
greatly appreciated.
Nov 14 '05 #1
6 4112
Try something like

#define AlphaWrap(c, n) ((c)-(n)<'A'?(int)'Z'+1+(c)-'A'-(n):(c)-(n))
Nov 14 '05 #2
Jeffrey Barrett wrote:
hello, i'm working on a decoder program that lets the user input a key
(integer between 0 and 26) and then subtracts that number from a given
letter to produce a decoded message. for example, 'Y' - 12 = 'M'. My
problem is I would like the program to "wrap around the alphabet" when
it subtracts the key from the original letter. Ex. 'B' - 5 = 'W'.
this must work for lower and uppercase letters. any help would be
greatly appreciated.


Use your favorite search engine for "ROT-13".

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #3
On 13 Jun 2004 15:29:09 -0700, on*********@hotmail.com (Jeffrey
Barrett) wrote in comp.lang.c:
hello, i'm working on a decoder program that lets the user input a key
(integer between 0 and 26) and then subtracts that number from a given
letter to produce a decoded message. for example, 'Y' - 12 = 'M'. My
problem is I would like the program to "wrap around the alphabet" when
it subtracts the key from the original letter. Ex. 'B' - 5 = 'W'.
this must work for lower and uppercase letters. any help would be
greatly appreciated.


char upper_case [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

Think about it, very useful in both directions.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
Martin Johansen <mf**@online.no> wrote in message news:<VL*******************@news2.e.nsc.no>...
Try something like

#define AlphaWrap(c, n) ((c)-(n)<'A'?(int)'Z'+1+(c)-'A'-(n):(c)-(n))


thanks for the help

im very new to c programming, could you explain what the c and n
variables would be?

thanks
Nov 14 '05 #5
Martin Johansen <mf**@online.no> wrote:
Try something like

#define AlphaWrap(c, n) ((c)-(n)<'A'?(int)'Z'+1+(c)-'A'-(n):(c)-(n))


You've tried this using EBCDIC, I suppose? Funny results, what?

Richard
Nov 14 '05 #6

"Jeffrey Barrett" <on*********@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Martin Johansen <mf**@online.no> wrote in message

news:<VL*******************@news2.e.nsc.no>...
Try something like

#define AlphaWrap(c, n) ((c)-(n)<'A'?(int)'Z'+1+(c)-'A'-(n):(c)-(n))


thanks for the help

im very new to c programming, could you explain what the c and n
variables would be?

thanks


It appears to be the char you want to encode, and the number of places to
shift for your encoding. e.g. to encode 'M' 12 spaces, then use
AlphaWrap('M', 12);
Allan
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dan V. | last post by:
Is it possible to have 2 divs beside each other and one not wrap around? I realize the 2 div's are floating left but I can only think of this as the best solution for now. I am trying to get...
3
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug...
5
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
8
by: Jack Addington | last post by:
I want to scroll through the alphabet in order to scroll some data to the closest name that starts with a letter. If the user hits the H button then it should scroll to the letter closest to H. ...
8
by: Mark D. Smith | last post by:
Hi I have googled but not found a solution to wordwrap in a textarea using firefox/netscape. is there a style sheet solution or am i stuck with not being able to force wrapping in a textarea...
31
by: Joe Smith | last post by:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" " " "!#%^&*()-_" "+=~\|;:\'" "\"{},.<>/\?" "\a\b\f\n\r\t\v\\" Do the above string literals comprise an alphabet for C?...
1
by: maya | last post by:
hi, I have to do a page where there's a paragraph with an img on top left and the text in paragr has to wrap around the image.. pls see screen-shot here......
20
by: geebanga88 | last post by:
HI i have a method that is supose to store the alphabet in an array however dont think that it is being added to the array. public static void GetAlphabet (char alphabet) { int...
8
by: Skeer | last post by:
This is what I'm having problems with: I have a image that is in an absolute positioned div at the bottom left of my content. I want the content to be full width until reaching the image then wrap...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.