0

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.

Community
  • 1
  • 1
  • 1
    `isalpha`. isvowel does not exist in standard C. `int x` --> `int x = 0`, `char tmparry[strlen(codeit)];` --> `char tmparry[strlen(codeit)+1];` then null-terminate. – BLUEPIXY Nov 24 '16 at 23:21
  • @BLUEPIXY Yeah that makes sense. Thank you thank you :) I didnt see how that could cause an issue in the future. – Pyth0nPr0grammer Nov 24 '16 at 23:26
  • By the way you have an obvious logic error in that a letter cannot be both a lowercase vowel and an uppercase vowel. – djechlin Nov 24 '16 at 23:29
  • @djchlin Well what I was aiming for is between a -> z, for every letter that isnt a vowel to have a code added to the end of it then append it to the new array. – Pyth0nPr0grammer Nov 24 '16 at 23:33
  • @DamaniAPhilip , what djechlin meant is that there is an error in the second if statement, a char cannot be uppercase and lowercase at the same time, its one OR the other. – Damian Chrzanowski Nov 24 '16 at 23:38
  • @DamianChrzanowski Thank you bro, as you probably can tell Im new to C. Python is way different lol. – Pyth0nPr0grammer Nov 24 '16 at 23:48
  • Python is super forgiving :) I love Python so so much :D Don't worry though, just gotta be more strict with C/C++ ;) – Damian Chrzanowski Nov 25 '16 at 16:15

1 Answers1

1

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

Community
  • 1
  • 1
djechlin
  • 59,258
  • 35
  • 162
  • 290