I'm trying to make a function check that first turns char *word to lowercase, then compares it to dictionary words stored in a linked list. I saw this post with similar title, but the issue seems different.
I'm getting the following error:
dictionary.c:171:23: error: variable 'temp' is uninitialized when used within its own initialization
And I know it's likely because I'm using a pointer for a char variable temp, while also using temp in temp's own initialization. I've tried a number of different things such as initializing temp with another name so I'm not using the same variable in its initialization. I keep getting errors. I'm quite new to C and would love some understanding on this.
my function is below:
// Returns true if word is in dictionary else false
//watch linked list vid
bool check(const char *word)
{
// TODO
printf("the word is %s", word);
//need to use case
node *cursor = head;
while(cursor != NULL)
{
//this will point to previous places in linked list
cursor = cursor -> next;
//make it lowercase
// if (isalpha(word) )
// {
// word = tolower(word);
// printf ("\n Lowercase of Entered character is %c", Ch);
// }
// char *temp = strdup(string); // make a copy
char *temp = strcpy (temp, word); // strlwr(word); //strdup(word); // make a copy
// adjust copy to lowercase //https://stackoverflow.com/questions/32063131/how-to-convert-constant-char-pointer-to-lower-case-in-c
unsigned char *tptr = (unsigned char *)temp;
while(*tptr) {
*tptr = tolower(*tptr);
tptr++;
}
//do things
// release copy
//free(temp);
//iterate through the char[]
int isEqual = 1;
int i = 0;
int j = 0;
while(temp[i] != '\0' || cursor->word[j] != '\0')
{
if(temp[i] != cursor->word[j])
{
isEqual = 0;
break;
}
i++;
j++;
}
if(isEqual == 1)
{
printf("EVEN STEVEN! %s", temp);
return true;
}
}
return false;
}