Jacomus
Jacomus

Reputation: 33

warning: format '%c' expects argument of type 'char *', but argument 3 has type 'int'

char *searcharray = malloc(size);
for (i = 0; i < size; i++)
{
  fscanf(filePtr, "%c", searcharray[i]);
}

Here is my code. And Everytime i keep getting the warning message:

warning: format '%c' expects argument of type 'char *', but argument 3 has type 'int'

How is the variable searcharray being determined as an int?

Upvotes: 3

Views: 5749

Answers (1)

Bill Lynch
Bill Lynch

Reputation: 82026

What's happening:

  1. searcharray[i] has type char.
  2. In a varargs function, the char will be promoted to an int.

Your bug:

  1. fscanf expects the variables that it will place data into to be passed by pointer.
  2. So you should be doing:

    fscanf(filePtr, "%c", &searcharray[i]);
    

Upvotes: 11

Related Questions