'C' Programming (CS215)

Discussion in 'Web Design & Coding' started by dal2lad, Oct 24, 2004.

  1. dal2lad

    dal2lad OSNN One Post Wonder

    Messages:
    5
    Location:
    TU
    'C' Programming HELP

    Hi,

    Any voluntier to help me in my 'C' Programming ?

    The Question:

    The fuction below needs to be run in a program.

    Write a fuction called ChangeToNext that take in an uppercase character parameter ch. The function returns the next upercase character if ch is between 'A' and 'Y'. If ch =='Z', the function returns 'A'. You may assume that the character parameter ch is always an uppercase alphabetic character.

    Thank you
     
  2. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    That question is very straight forward. If you can't solve it I suggest you read up on what you're supposed to do. I could write it for you, but what good would it do?

    At least give it a try. If you can't get it right, post back with what you have and well try to see what's wrong with your code. Good luck! :)
     
  3. dal2lad

    dal2lad OSNN One Post Wonder

    Messages:
    5
    Location:
    TU
    Thank you for your advice. I will try
     
  4. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    This is simple to write. Just a hint:

    char blah = 'A';
    int num = blah;

    prinft ("%d", num);

    Should print a number, not the character A. Use this to your advantage, as

    char B = (int)A + 1;

    So all you really need to check, is if it is Z before you do that, and if it is Z, then set char equal to A.

    Damnit, allready gave you to much info. Good luck.
     
  5. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    google ASCII Tables
     
  6. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    To many hints :p
     
  7. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    /me wants to see the code ;) damn it this is so much like stuff I do in machine code - I love seeeing thing stuff in C and laughing when it is the same # of lines as my assembler (well - nearly!)
     
  8. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    I want to see his code when hes got it sorted :p
     
  9. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    does this mean you finished the first one? Post it up if you want more help (got to learn step 1 before step 2?)
     
  10. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Lets see the first one.
     
  11. dal2lad

    dal2lad OSNN One Post Wonder

    Messages:
    5
    Location:
    TU
    I'm still stragling...:)
     
  12. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    awwww dear - stragling sounds even worse than struggling ;) :p
     
  13. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Yeah, like strangling. Maybe he got hung in a loop? ;) :D





    Oooohh bad one!
     
  14. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    I kinda liked the really corny joke.
     
  15. He doesn't really need ASCII table coz he's only going to work from A to Z which is 65 to 91
     
  16. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Not everyone knows that off the top of their head :p
     
  17. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    quite true, like my Networks and Communications lecturer for example, though it was more odd when he said that lower case started at 41 and upper case started at 61

    i mean you can just think about that and know its wrong, theres only 20 characters between 41 and 61, so not enough space. But then he was right about where the upper case started, well close enough :p
     
  18. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    First - just off my head I kinow he was right and you are also wrong, you see in HEX the numbers add up fine.....

    Second you got it back to front - UPPER case starts at x'41' and LOWER ar x'61'

    Sorry to be a smart ass, but I thought I should clear that up, since this is meant to be a "learning" thread ;)
     
  19. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    Agreed - plus if he starts to embed things like ASCII tables he may actually LOSE points since it will lose cross platform portability, say if it had to compile and run with EBCDIIC instead (where the alpha characters are not even consecutive :eek::)
     
  20. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Wouldn't

    if chr == 'Z' then
    return 'A'
    else
    return chr+1

    work? Without having to complicate things with ASCII tables...

    (not in C notation I know, but it was on purpose ;))