-1

Well, I have the problem with the data updating in my counter int x. I am passing a lot of char* strings to my function, e.g. when I pass first char* of the length of 8, int x will be 8. Then if I pass the next char* of the length of 11, x still will hold the value of 8. Any advice on fixing it?

bool check(const char* word)
{
    char checker[LENGTH+1];
    int x = sizeof(word);

    for(int a=0; a<x; a++) {
        checker[a] = word[a];
    }

    for(int i=0; i < x-1; i++) {
        //check if all chars are lower-case
        if(checker[i] < 'a' && checker[i] != '\'') {
        checker[i] = tolower(checker[i]);
        }
    }
} 
Pavel Vasiluk
  • 317
  • 2
  • 12

1 Answers1

1

sizeof(word) is giving you the size of your pointer. Use strlen instead to get the length of the string.

Also a style note, x isn't a great name for a variable that stores a string length, I'd name it something more to do with what it's actually used for.

Peanut
  • 2,221
  • 1
  • 26
  • 37