Thread: string to ASCII and back...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    4

    Question string to ASCII and back...

    Hi!
    i have to write a program that will ask user to enter an unsigned integer and any string and then my program has to output new string which is the old string transfered into ASCII + unsigned integer so for example if I enter 3 and "abc" output should be "def"
    ('a' shifted to 'd', 'b' to 'e', and 'c' to 'f')

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    We are not here to do your homework for you. Read the forum rules, follow them, then check back once you have done so.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    read the number and the string into a character array

    use the space for separating the number from the string

    find the ASCII value of each letter in the string and the add the number to it if it's within the correct range (isalpha) else output an error message.

    rebuild the string, and spit it back out.

    char mystr[2][16];

    mystr[0] can be the read string and mystr[1] can be the new string.

    Perhaps not the most useful method, but it *should* do.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    printf("%c",my_string[i]+3);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  3. Problem writing ASCII characters in file
    By sho1 in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2006, 01:51 PM
  4. Casting strings to integers and back
    By clancyPC in forum C Programming
    Replies: 7
    Last Post: 11-20-2003, 01:05 AM
  5. Binary to ascii and vice versa
    By thenrkst in forum C++ Programming
    Replies: 13
    Last Post: 03-30-2003, 01:17 AM