0

My code:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
    char* extension = "CSS";


    int n = strlen(extension);
    for (int i = 0; i < n; i++)
    {
        extension[i] = tolower(extension[i]);
    }

    printf("%s\n", extension);
}

I'm trying to convert a string to lowercase

0

Your problem lies here:

char* extension = "CSS";

You are creating a pointer to a char and then assigning it to the start of a string. Later, you're trying to use it like an array. While it does the assignment, it leads to some anomalies when you try to access the letters later. Instead, try creating it as a char array.

char extension[] = "CSS";

This will fix it, but I'll leave it to someone like @Kareem to explain the subtleties of what's going on.

If this answers your question, please click the check mark to accept. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .