Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

23warning: assignment makes pointer from integer without a cast [duplicate]

Im new in programming c with arrays and files. Im just trying to run the following code but i get warnings like that:

23 44 warning: assignment makes pointer from integer without a cast

53 error: expected expression before ‘char’

Any help? It might be silly... but I cant find what's wrong.

#include <stdio.h>

FILE *fp;
FILE *cw;
char filename_game[40],filename_words[40];

int main()
{
    while(1)
    {
         /* Input filenames. */
            printf("\n Enter the name of the file  \n");
            gets(filename_game);
            printf("\n Give the name of the file2 \n");
            gets(filename_words);

         /* Try to open the file with the game */
            fp=fopen(/* args omitted */);                             //line23**
            if   (fp!= NULL)     
            {  
                printf("\n Successful opening %s \n",filename_game); 
                fclose(fp);
                puts("\n Enter x to exit,any other to continue! \n ");
                if ( (getc(stdin))=='x')
                   break;
                else
                    continue;
            }
            else
            {
                fprintf(stderr,"ERROR!%s \n",filename_game);
                puts("\n Enter x to exit,any other to continue! \n");
                if (getc(stdin)=='x')
                   break;
                else
                    continue;
            }

              /* Try to open the file with the names. */            //line 44**
              cw=fopen(/* args omitted */);
             if   ( cw!=NULL )   
            {  
                printf("\n Successful opening %s \n",filename_words); 
                fclose(cw);
                puts("\n Enter x to exit,any other to continue \n ");
                if ( (getc(stdin))=='x')                         
                   break;                                          //line 53**
                else
                continue;
            }
            else
            {
                fprintf(stderr,"ERROR!%s \n",filename_words);
                puts("\n Enter x to exit,any other to continue! \n");
                if (getc(stdin)=='x')
                   break;
                else
                    continue;
            }
    }   
    return 0;
}
like image 822
FILIaS Avatar asked Feb 16 '26 14:02

FILIaS


1 Answers

You are missing parentheses here:

if (fp=fopen("crypt.txt","r")!=NULL)

The != operator has higher precedence than = so the compiler sees the expression like this:

if ( fp = ( fopen("crypt.txt","r") != NULL ) )

fp gets either 1 or 0 depending on whether fopen returned NULL. fp is a pointer and 0/1 is an integer, hence the warning.

You want

if ( ( fp=fopen("crypt.txt","r") ) != NULL )
like image 172
Potatoswatter Avatar answered Feb 18 '26 08:02

Potatoswatter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!