'I don't know why my code can't handle non numeric keys

please I'm having this issue with my code. it keeps telling me that it can't handle a non numeric key each time a run a test on the program using cs50......

 for(int i = 0; i < text[i]; i++)
    {
       text[i] = rotate(text[i], key);
       printf("%c", text[i]);
    }
        printf("\n");
        return 0;

I think the error is within this for loop, because someone told me my loop doesn't have a stop condition, and I don't seem to understand what he meant.



Solution 1:[1]

Your test seems incorrect: i < text[i], you should instead test if text[i] is a null terminator.

Here is a modified version:

int rotate_string(char *text) {
    for (size_t i = 0; text[i] != '\0'; i++) {
        text[i] = rotate(text[i], key);
        printf("%c", text[i]);
    }
    printf("\n");
    return 0;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1