elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / No entiendo por qué se puede usar esta función ¡si no debiera! en: 2 Noviembre 2014, 13:49 pm
Hola amigos.
Estoy aprendiendo C y estaba repasando en mi libro de texto el uso de los archivos header o cabecera. Yo me hice un ejercicio compuesto de 4 archivos, que son los siguientes..

  • main.c
  • funciones.c
  • funciones.h
  • global.h

main.c
Código:
#include "global.h"
#include "funciones.h"

int main(int argc, char** argv) {
    int i;
    char a, b, c;
    for (i = 1; i < 3; ++i) {
        printf("Introduzca primer caracter: ");
        scanf("%c", &a);
        printf("Introduzca segundo caracter: ");
        flush_in();
        scanf("%c", &b);
        printf("Introduzca tercer caracter: ");
        flush_in();
        scanf("%c", &c);
        printf("Los valores son: %c, %c, %c \n", a, b, c);
        flush_in();
    }
    return (EXIT_SUCCESS);
}


funciones.c
Código:
#include "funciones.h"

/* Limpia buffer de entrada */
void flush_in(void) {
    int ch;
    while ((ch = fgetc(stdin)) != EOF && ch != '\n') {}
}


funciones.h
Código:
#ifndef YA_INCLUIDOS_FUNCIONES_H
#define YA_INCLUIDOS_FUNCIONES_H

#include "global.h"

#endif /* YA_INCLUIDOS_FUNCIONES_H */


global.h
Código:
#ifndef GLOBAL_H
#define GLOBAL_H

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

#endif /* GLOBAL_H */


Bien, lo que yo no entiendo es ¿cómo puede el compilador hallar la función flush_in en main.c si el header (funciones.h) ni siquiera exporta el prototipo?

Pido disculpas si la pregunta es muy noob, pero yo no la sé :D ...







Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines