2012-02-19 4 views
0

я получаю следующее предупреждение, когда я пытаюсь скомпилировать код:GCC предупреждение компилятора: формат «% с» ожидает аргумент типа «символ *», но аргумент 2 имеет тип 'INT * [-Wformat]

exercise6.c: 32: 14: warning: format '% c' ожидает аргумент типа 'char *', но аргумент 2 имеет тип 'int *' [-Wformat]

Что вызывает это предупреждение и как это сделать? Я чиню это?

/*Write a program that displays the contents of a file at the terminal 20 lines at 
a time. At the end of each 20 lines, have the program wait for a character to be 
entered from the terminal. If the character is the letter q, the program should 
stop the display of the file; any other character should cause the next 20 lines 
from the file to be displayed.*/ 

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

int main (void) 
{ 
    int c, i; 
    FILE *file; 

    if ((file = fopen ("text", "r")) == NULL) 
    printf ("Error opening the file.\n"); 

    for (i = 0; i < 20;) { 
     c = getc (file); 

     if (c == EOF) { 
      fclose (file); 
      exit (EXIT_SUCCESS); 
     } 

     putc (c, stdout); 

     if (c == '\n') 
      ++i; 

     if (i == 20) { 
      scanf ("%c", &c); 
      if (c == 'q') { 
       fclose (file); 
       exit (EXIT_SUCCESS); 
      } 
      i = 0; 
     } 
    } 
} 

ответ

5

Определить char ch и использовать его в scanf.

int c, i; 
char ch; 

/* ... */ 
scanf ("%c", &ch); 

Использование несоответствующих аргументов для scanf технически неопределенное поведение.

Смежные вопросы

 Смежные вопросы