pointer char[], help with warning

This is a discussion on pointer char[], help with warning within the C Programming forums, part of the General Programming Boards category; I'm getting the following error althrough the program is compiling a exe. I've been learning pointers and while playing with ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    36

    pointer char[], help with warning

    I'm getting the following error althrough the program is compiling a exe. I've been learning pointers and while playing with integers was fine, adopting the same stragety with a character array of 4, this warning is cropping up.

    error: incompatible types in assignment
    warning: passing arg 1 of `setAlphaPosition' from incompatible pointer type
    function prototype in place.
    Code:
    void setAlphaPosition(char *alphaPos[4], int x);
    declaration is as follows:
    Code:
    char alphaPosition[4];
    calling the function below:
    Code:
    setAlphaPosition(&alphaPosition, 3);
    Code:
    void setAlphaPosition(char *alphaPos[4], int x)
    {
        /* uses pointer to update string with the 
        alphabetical expression given in regards 
        to position, first, second, third etc .. */
        if ( x == 0 )
            *alphaPos = "1st";
        else if ( x == 1 )
            *alphaPos = "2nd";
        else if ( x == 2 )
            *alphaPos = "3rd";
        else if ( x == 3 )
            *alphaPos = "4th";
        else if ( x == 4 )
            *alphaPos = "5th";
        else if ( x == 5 )
            *alphaPos = "6th";
    }
    Anyone know what needs adjusting.
    Last edited by Cero.Uno; 04-26-2008 at 06:20 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    void setAlphaPosition(char alphaPos[4], int x)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Quote Originally Posted by Dave_Sinkula View Post
    Code:
    void setAlphaPosition(char alphaPos[4], int x)
    Adjusting the prototype to reflect your adjustment results in the following:

    warning: passing arg 1 of `setAlphaPosition' from incompatible pointer type
    top level:
    error: conflicting types for 'setAlphaPosition'
    error: previous declaration of 'setAlphaPosition' was here
    error: conflicting types for 'setAlphaPosition'
    error: previous declaration of 'setAlphaPosition' was here

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Make up your mind what you're actually trying to send to the function.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Quote Originally Posted by MacGyver View Post
    Make up your mind what you're actually trying to send to the function.
    I want the memory address of string alphaPosition sent to the function hence why I'm using the & operator before the string when passing the parameter.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok he meant to change the whole thing. But I know Todd also didn't notice what you are trying to do.

    Example:
    Code:
    char x[5] = "hi";
    strncpy(x, "hi", sizeof(x));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-12-2007, 06:26 PM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 02:09 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21