Thread: help in c with ascii

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    4

    help in c with ascii

    good morning everyone

    I m working on a program in c and i want to
    check a string if all characters are capitals and between A-Z(english).
    So the way i have to do it is by checking the ascii value of each character in the string given(ex str).

    Can anyone help me with this .??
    thank u very much..

    //admins sorry if i have posted in the wrong place//

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The standard header <ctype.h> provides an isupper() function that you may find handy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    If you give it a try then show us your code or errors then we could probably help better.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    thank u very much..I ll try it later and i will return with code ..

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    or u could do it manually

    Code:
    if( ch >= 65 && ch <= 90 )
    
    or
    
    if( ch >= 'A' && ch <= 'Z' )
    encapsulate this code with the function. And just call the function.

    ssharish

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by ssharish2005 View Post
    or u could do it manually

    Code:
    if( ch >= 65 && ch <= 90 )
    
    or
    
    if( ch >= 'A' && ch <= 'Z' )
    encapsulate this code with the function. And just call the function.

    ssharish
    Never do that. It isn't portable because it will only run on ASCII platforms.
    Even if your code is currently only running on an ASCII platform, you never know how long your code will survive and what platforms it will be ported to.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    How about unicode? Or maybe it isn't supported on all platforms?

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    So just in curious which machine donst support ASCII?

    ssharish

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by ssharish2005 View Post
    So just in curious which machine donst support ASCII?

    ssharish
    z/OS Mainframes would be one.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by ssharish2005 View Post
    So just in curious which machine donst support ASCII?

    ssharish
    More important question:
    How can somone looking at the code confirm that it is correct?
    Or
    In which piece of code is someone more likely to notice an off-by-one error?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Hello again..
    thanks everyone for advise

    i m just wondering
    how the code from ssharish would work for the whole string(example given string saved in str variable)
    and
    what about using the function isupper();
    (to remember I want all letters in caps betweeen A-Z)!
    I 've never used this one.If anyone can give me an example for sth string str...
    and i think this can be in a new function so it will be called after user gives the phrase!..

    Thank u all

  12. #12
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Use toupper() on each character in the string to convert to uppercase.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM