Thread: Pointer Help [rookie in C]

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    2

    Pointer Help [rookie in C]

    Hi, im new at C so I dont understand that much yet about pointers...

    what i have is this function:
    Code:
    char * currentboard(void *arg)
    {
        static char  result;
        result = currentBoard("XXX");
    
        return &result;
    }
    XXX - this argument must be *char, but i want to use the "arg" *void that is above as an input. thefore I have to cast from void to char, so I do: (char*)argp. Then the complment statement is:

    result = currentBoard((char*)argp);

    But when I'm going to compile I got this error:
    "error: void value not ignored as it ought to be"

    So, what am I doing wrong ? plz help!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    88
    Quote Originally Posted by toshX View Post
    Hi, im new at C so I dont understand that much yet about pointers...

    what i have is this function:
    Code:
    char * currentboard(void *arg)
    {
        static char  result;
        result = currentBoard("XXX");
    
        return &result;
    }
    XXX - this argument must be *char, but i want to use the "arg" *void that is above as an input. thefore I have to cast from void to char, so I do: (char*)argp. Then the complment statement is:

    result = currentBoard((char*)argp);

    But when I'm going to compile I got this error:
    "error: void value not ignored as it ought to be"

    So, what am I doing wrong ? plz help!
    B]"error:[/B] void value not ignored as it ought to be[B]"
    usually means your assigning a value a function call where the function is void

    Code:
    void 
    nop(void *a)
    {
    }
    
    
    char *b = nop(NULL);  /** <--- this should give you that error **/

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    2
    But is nothing about malloc ? I mean, when you are converting void to char you dont need to put malloc ?

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by toshX View Post
    But is nothing about malloc ? I mean, when you are converting void to char you dont need to put malloc ?
    What?! o_O
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rookie looking for help!
    By Newklear in forum C Programming
    Replies: 28
    Last Post: 03-11-2011, 05:15 AM
  2. C++ Rookie.
    By forexsurfr in forum C++ Programming
    Replies: 3
    Last Post: 10-01-2010, 10:13 AM
  3. Variable/pointer scope (rookie Qs)
    By twinbee in forum C Programming
    Replies: 3
    Last Post: 05-20-2010, 03:33 PM
  4. Help a rookie
    By elrookie in forum C Programming
    Replies: 14
    Last Post: 06-14-2007, 10:28 AM
  5. Rookie pointer problem: 2 dimensions, malloc
    By GatesAntichrist in forum C Programming
    Replies: 11
    Last Post: 12-20-2005, 12:35 PM