Thread: passing arg makes pointer to integer without a cast

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    26

    passing arg makes pointer to integer without a cast

    From the code below i get the following warning message from the display_char function.

    warning: passing arg 1 of 'valid char' makes pointer to integer without a cast

    Code:
    void display_char(char c, char position)
    {
            if(position > 5)
            {
            	return;
            }
            if (valid_char(c) == 0);
            {
            	return;
            }
    
            TextBuffer[position] = c;   
    }

    Code:
    int valid_char(char *check)
    {
            char i,j, k;
            char validChar[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '+', '-', '.', ' ', '_', '\0'};
            char validCharSize = 0;
            char inputCharSize = 0;
            char valid = 0;
            
            for(i = 0; validChar[i] != '\0'; i++)
            {
                    validCharSize++;        
            }
            
            for(i = 0; check[i] != '\0'; i++)
            {
                    inputCharSize++;        
            }
            
            for(j = 0; j <= inputCharSize; j++)
            {
                    for(k = 0; k < validCharSize; k++)
                    {
                            if(check[j] == validChar[k])
                            {
                                    valid++;
                            }
                    }
            }
            
            if(valid == inputCharSize)
            {
                    return 1;
            }
            else
            {
                    return 0; 
            }
    }
    I don't really get what the warning message is saying and so it was no surprise to be when my attepmts to fix this failed.
    Any help would be greatly appreciated.

    Thanks
    -Nick
    Last edited by Rad_Turnip; 07-11-2006 at 03:31 PM.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    The message is pretty strait forward.

    char c in display_char() is a char. valid_char() takes a char pointer. So your character is being implisidly typecast as a char pointer.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    26
    Hi

    thanks for the reply

    I'm not at my the computer with the code on it right now so i can't test my guess.

    I assume the problem is solved by passing the pointer *c instead of the char itself to valid_char.

    correct?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If all you are doing is testing a single character, just pass a character and don't bother passing a pointer.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    &c actually, but that still won't solve your problem because valid_char() expects a null terminating string.

    You could either create a 1 char string in display_char(), or probably better change/make a new function for valid_char() that takes a single character.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  2. File Server Help
    By lautarox in forum C Programming
    Replies: 146
    Last Post: 09-24-2008, 06:32 PM
  3. "assignment makes integer from pointer without a cast"
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-04-2002, 04:26 AM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM