Damani A Philip Damani A Philip - 9 days ago 5
C Question

comparing against both lowercase and uppercase.

Happy Thanksgiving if it applies. I am trying to create a function I will be able to use in the future. The function should be able to accept a char array and code it. (I am not finished with the code part)

int codetut(char *codeit){
int x,y = 0;
char tmparry[strlen(codeit)];
while(codeit[x] != '\0'){
if((codeit[x] >= 'a' && codeit[x] <= 'z') || (codeit[x] >= 'A' && codeit[x] <= 'Z')){ //Set to look for capitals and commons
if((codeit[x] == 'a' || codeit[x] == 'e' || codeit[x] == 'i' || codeit[x] == 'o' || codeit[x] == 'u') && (codeit[x] == 'A' || codeit[x] == 'E' || codeit[x] == 'I' || codeit[x] == 'O' || codeit[x] == 'U')){ // set to look for vowels
tmparry[y] = codeit[x];

x++,y++;
}else{

x++,y;
}
}else{
tmparry[y] = codeit[x];
x++,y++;
}
}
printf("%s",tmparry);
return 0;
}


I was looking here how to validate both lowercase and uppercase letters. Unfortunately I did not find what I was looking for.

Question:


  1. Is there a better way to compare the pointer to both uppercase and lowercase versions?



Just one request, if you know a post that will help me please point me to it.

Answer

Convert the character to lower first, then do the comparisons.

tolower is the method for this. See e.g. c - convert a mixed-case string to all lower case

Comments