Thread: 'Makes pointer from integer without a cast'

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    'Makes pointer from integer without a cast'

    New to C. I do realize that there are threads about this problem everywhere, but I've searched through at least half of them and haven't yet found one that properly applied to this situation.

    I get the warning "passing arg 1 of `strcpy' makes pointer from integer without a cast". I know what this means but I don't know how to fix it in this case.

    Code:
    /* Declare variables */
    char command[50][10]; /* Array to store commands into */
    int i, j, k, l, m = 0; /* Counter variables for command storage */
    
    int main( void )
    {
    
        /* Declare variables */
        FILE *file; /* File used for reading */
        char *tokenPtr; /* Current word being read */
        char fileName[6]; /* File name */
        
        /* Arrays */
        char line[80][50]; /* Array to store line in the file */
    
        /* Iterate through the lines array */
        for( j = 0; j < i; j++ ) {
    
            /* Tokenize line with a space, new line, and tab delimiter */
            tokenPtr = strtok( line[j], " \n\t" );
            /* Convert tokenized into upper case */
            *tokenPtr = toupper( *tokenPtr );
    
            /* As long as there are still more words to be read */
            while( tokenPtr != NULL ) {
    
                /* Copy the line's words into the command array */
                strcpy( command[j][k], tokenPtr );
                /* Increment counter for second index */
                k++;
    
                /* Get next token */
                tokenPtr = strtok( NULL, " \n\t" );
    
            }
            
            k = 0;
        }
    
    }
    Next part, I want to compare a value to NULL. I would just like to ask if this would be the same thing as comparing to zero.

    Code:
       /* Determine error type and print out corresponding error message */
        if( command[m][1] < 0 ) {
            printf( "\nError: Parameter cannot have a value under 1.", command[m][0] );
        } else if( command[m][1] == 0 ) {
            printf( "\nError: Command %s takes in an int parameter.", command[m][0] );
        }
    Thanks for any help!

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    command[j][k] is of type char and holds a single char, so you can't just copy an entire string into it.

    > Next part, I want to compare a value to NULL. I would just like to ask if this would be the same thing as comparing to zero.

    It's better to use NULL if you're comparing pointers. It's more accepted to use 0 instead of NULL when programming in C++ though.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Not to mention:
    Code:
    int i, j, k, l, m = 0; /* Counter variables for command storage */
    
    int main( void )
    {
    
        /* Declare variables */
        FILE *file; /* File used for reading */
        char *tokenPtr; /* Current word being read */
        char fileName[6]; /* File name */
        
        /* Arrays */
        char line[80][50]; /* Array to store line in the file */
    
        /* Iterate through the lines array */
        for( j = 0; j < i; j++ ) {
    ...
    You're using 'i' without initialising it.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Memloop View Post
    ...It's more accepted to use 0 instead of NULL when programming in C++ though.
    Absolutely not. Don't say such things.
    This is trend that will be phased out.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    > Absolutely not. Don't say such things.

    What's not right about it? Almost every single C program uses NULL when comparing pointer values, but there are many C++ programs (most that I've seen anyway) that compare against 0 instead of NULL since Stroustrup recommends it.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I only see that he prefers to avoid macros. But as I said, while legal, it's a dying trend. In C++0x, it's nullptr, and NULL and 0 will be kept only for backwards compatibility.
    Besides that, there is a NULL pointer, but there isn't a 0 pointer.
    Similarly, there isn't a NULL value, but there is a value 0.
    So to sum it up: don't use 0. Use NULL. Or better yet, nullptr.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-12-2010, 10:26 AM
  2. makes pointer from integer without a cast
    By nyquil in forum C Programming
    Replies: 5
    Last Post: 05-06-2010, 06:40 AM
  3. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 08:38 PM
  4. help with error message
    By ddolddolee82 in forum C Programming
    Replies: 10
    Last Post: 05-07-2006, 09:37 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM