-
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;
}
-
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)
-