Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/11/2013, 10:16
vosk
 
Fecha de Ingreso: agosto-2012
Mensajes: 601
Antigüedad: 11 años, 8 meses
Puntos: 83
Respuesta: Error en sencillo programa en C

Una nota sobre fflush(stdin), esta es la referencia de la funcion:

Código C:
Ver original
  1. int fflush(FILE *ostream);
  2.  
  3. ostream points to an output stream or an update stream in which the
  4. most recent operation was not input, the fflush function causes any
  5. unwritten data for that stream to be delivered to the host environment to
  6. be written to the file; otherwise, the behavior is undefined.

Eso significa que aunque en determinadas implementaciones la funcion haga lo que se espera, esa funcion no está pensada para trabajar con el FILE* stdin. La alternativa es forzar la lectura de la cola de entrada estandar hasta vaciarla:

Código C:
Ver original
  1. void fflush_stdin() {
  2.     char c;
  3.     while ((c = getchar()) != '\n' && c != EOF);
  4. }
  5.  
  6. //y la ejecutas antes de cada scanf
  7. fflush_stdin();
  8. scanf("lo que sea");

Saludos
vosk