#Recursive function help

6 messages · Page 1 of 1 (latest)

vapid wyvern
#

Here is the code:

        int var = 0;
        if (strcmp(firstNode->name, name) == 0) {
                var = 1;
                return var;
        }
        if (firstNode->next == NULL) {
                return var;
        }
        else {
                searchNode(firstNode->next, name);
        }
        return var;
}```
firstNode is a self-referential structure that essentially is an array but harder to deal with. The "next" value in the structure is the next node that is "in line". Im trying to recursivly loop through the "array" and return 1 if name is the the "array", and 0 if not. For some reason, it always returns 0. This is probably some stupid mistake, but I cant figure it out
low oceanBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lost idol
#

return searchNode(firstNode->next, name);

vapid wyvern
lost idol
#

else

vapid wyvern