Thread: Void value not ignored as it ought to be [I DO RETURN SOMETHING!]

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    12

    Void value not ignored as it ought to be [I DO RETURN SOMETHING!]

    Error: void value not ignored as it ought to be


    I looked up this error online and most issues seemed to be associated with not returning anything, or putting the return statement in an if block. I do no such thing. What's going on?

    *******IMPORTANT****** Even if I put this before the first if statement in the function, I still get the same error!

    Code:
    char *a = "lel";
    return a;
    FUNCTION:

    Code:
    char *list_groups(Group *group_list) {
        Group * current = group_list;
        char *groupList;
        // What if there are no groups, do I have to strcpy an empty string?
        if ((groupList = malloc(sizeof(char))) == NULL) {
            perror("Error allocating space for the string groupList");
            exit(1);
        }    
        while (current != NULL) {
            if ((groupList = realloc(groupList, sizeof(groupList) + sizeof(current->name) - 1)) == NULL) {
                perror("Error resising the memory allocated to groupList");
                exit(1);
            }
            strcat(groupList, strcat(current->name, "\n"));
            current = current->next;
        }    
        return groupList;
    }
    FUNCTION CALL:
    Code:
    char buffer;
    
    //the above statement is not actually above the else if statement. 
    
    } else if (strcmp(cmd_argv[0], "list_groups") == 0 && cmd_argc == 1) {
            buffer = list_groups(group_list);
            printf("%c", buffer);
    Last edited by pointingmachine; 04-04-2013 at 08:22 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You need to fix the problem I mentioned in your other thread. Furthermore, you need to post the exact error message and tell us which line does it refer to.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    12
    Quote Originally Posted by laserlight View Post
    You need to fix the problem I mentioned in your other thread. Furthermore, you need to post the exact error message and tell us which line does it refer to.
    For this problem, it's line 6, the function call : buffer = list_groups(group_list);

    I will revisit the other thread

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pointingmachine
    For this problem, it's line 6, the function call : buffer = list_groups(group_list);
    One problem with that line is that list_groups returns a char*, but buffer is a char. buffer should be a char* instead. The error message does not make sense, but that's probably because the mistake is in a part of the code that you did not show.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    12
    Yes, the issue was in the header file, the return values of the functions in the header file were different. I got my old error back in the other thread, and now I am debugging again. Will update soon. Please check back when you can. I shouldn't be too long.

    The return value for this function was null in the header file...I WOULD HAVE NEVER GUESSED, because the header file was provided with the assignment...
    Last edited by pointingmachine; 04-04-2013 at 09:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to return in void function();
    By pczafer in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2009, 03:06 PM
  2. return something in a void
    By vrkiller in forum C++ Programming
    Replies: 11
    Last Post: 02-10-2009, 07:25 PM
  3. void return
    By l2u in forum C++ Programming
    Replies: 20
    Last Post: 12-15-2006, 11:55 AM
  4. return void * size_t
    By matott in forum C Programming
    Replies: 2
    Last Post: 10-16-2005, 12:31 PM
  5. Void return type
    By Spectrum48k in forum C Programming
    Replies: 5
    Last Post: 05-29-2002, 09:44 AM