I'm trying to understand the black voodoo magic that are pointers and I can't get my head around the following cases. My understanding of the first parameter of getline() is clumsy, so I guess it all comes down to its type, which is different from the word in the second example.
The following is an extract from a function that loads a file (a dictionary of words) and reads its content line by line. Why does tolower() work in this first example:
int l;
size_t len = 0;
char *word = NULL;
while ((l = getline(&word, &len, fp)) != -1)
{
for (char *p = word; *p; ++p) *p = tolower(*p);
// Irrelevant code below
}
But segfaults in this second example, right after trying to assign the return of tolower() from the first char:
char *word = "POTATO";
for (char *p = word; *p; ++p) *p = tolower(*p);