help with function args

This is a discussion on help with function args within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int check(int a) { FILE * Tmp; if ( ( Tmp = fopen(a, "r+") ) == 0 ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    help with function args

    Code:
    #include <stdio.h>
    
    int check(int a)
    {
            FILE * Tmp;
            if ( ( Tmp = fopen(a, "r+") ) == 0 )
            {
                    printf("no");
            }
            else
            {
                    printf("yes");
            }
            fclose(Tmp);
            return 0;
    }
    
    int main()
    {
            check("read.txt");
            return 0;
    }
    Passing argument 1 of fopen function makes pointer from integer without a cast.

    This was only a warning from the compiler. This works, but why am I getting the warning? I was trying to put the same concept as the following into a file existance check....

    Code:
    int display_message(int a)
    {
            printf("The color you have chose is %s", a);
            printf("Bla bla bla...");
            return 0;
    }
    The world is waiting. I must leave you now.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Well they're both wrong

    > Passing argument 1 of fopen function makes pointer from integer without a cast
    You pass an int (a), and it expects a char *
    So you get a warning about casting ints to pointers


    int check(int a)
    should be
    int check(char *a)

    And
    int display_message(int a)
    should be
    int display_message(char *a)

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Oh, I see. Thanks Salem.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 08:29 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

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