Thread: ascii

  1. #1
    Sometimes so stupid... shardin's Avatar
    Join Date
    Jul 2007
    Location
    Dalmatia/CRO
    Posts
    78

    ascii

    I need to identify how many vowels i have in a sentence, how many consonants, and how many other signs like ?,;,%...
    I have a field for vowels like this
    Code:
    char samoglasnik_p[]={'a','A','e','E','i','I','O','o','U','u'};
    , so i compare them and that works but the rest is fu****. I don't know how to tell to program how to recognize consonants and other signs. Is there any way to do this? I tried to do something like this but...
    Code:
    if((buffer[i]>='a' && buffer[i]<='z' != samoglasnik_p[i])==k)
    help

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Same way you did the vowels can be used to do the other types. Have an array for the other chars and go from there.

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Code:
    if((buffer[i]>='a' && buffer[i]<='z' != samoglasnik_p[i])==k)
    That doesn't seem right. What that is saying is "if buffer[i] is greater than 'a' (correct) AND
    buffer[i] is less/equal to 'z' also not equal to samoglasnik_p[i] and also equal to k"
    you're basically comparing the variable k to samoglasnig_p[i], 'z' and buffer[i]. I doubt that would ever give you a correct value ;-)

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Sometimes so stupid... shardin's Avatar
    Join Date
    Jul 2007
    Location
    Dalmatia/CRO
    Posts
    78
    i did it now, it is working, i used this
    Code:
    char samoglasnik_p[]={'a','A','e','E','i','I','O','o','U','u'};
    char as[10]={'!','"','.','?','+',';','-',':',' ','*'};
    and i compare them, its working. But is there a way to tell to program which sign is number, letter or other signs, without the need to put them into fields.

    for exp. by putting
    Code:
    buffer[i]>='a' && buffer[i]<='z'
    i included all letters from a to z, only lower case but... do you get my point?

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Why don't you use isalpha() to check whether it is a letter, isdigit() to check whether it is a number and everything else is something else.
    tolower() will take the pain of comparing upper and lowercase letters ;-)

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    isdigit()
    isalpha()
    ispunct()
    isspace()...

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    All of which are located in <ctype.h>.

    I've also seen strchr() (in <string.h>) used for this purpose.
    Code:
    char c = 'I';
    if(strchr("aeiou", tolower(c))) {
        printf("'&#37;c' is a vowel.\n", c);
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

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