-
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
-
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.
-
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
-
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?
-
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
-
isdigit()
isalpha()
ispunct()
isspace()...
-
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("'%c' is a vowel.\n", c);
}