Invalid argument of type '->' C

I keep getting the error

invalid type argument of '->' (have 'int') 

      

on the line marked with arrows when trying to read the contents of an input file from a separate function.

It works if it is stored in the main program. I realize this probably has something to do with pointers, but I can't seem to fix it.

#include <stdio.h>
#include <stdlib.h>

void function1(file_a);

int main()
{

   FILE *file_a = fopen("input.txt", "r");

   if (file_a != NULL){

       void function1(file_a);
   }
   else{

   }

}

void function1(file_a)
{

   while(!feof (file_a)) <<<<<<<<
   {

   }

}

      

+3


source to share


3 answers


Change to:



void function1(FILE * file_a);

///

    void function1(FILE * file_a)
    {

       while(!feof (file_a))
       {

       }

    }

      

+5


source


You didn't give a file_a

type, so it was default int

, try this:



void function1(FILE* file_a);

...

void function1(FILE* file_a)
{
    ...

      

+5


source


Also, don't add the return type of the called function. You should only specify this when declaring / defining a function:

if (file_a != NULL){

       void function1(file_a); // <<< remove "void"
}

      

+1


source







All Articles