I'm doing my university project and I'm creating several libraries, among them I have these
#include "menus.h"
#include "usuario.h"
#include "listaMaterias.h"
#include "validacion.h"
The problem I have is that the library "validacion.h"
I'm using also in the libraries "usuario.h"
and "listaMaterias.h"
and when I compile my main program I mark some errors referring to the library of "validacion.h"
but I do not know how solve it.
In file included from listaMaterias.h:5:0,
from menu.c:5:
validacion.h:12:6: error: redefinition of ‘validarNumero’
bool validarNumero(char numero[])
^
In file included from usario.h:5:0,
from menu.c:4:
validacion.h:12:6: note: previous definition of ‘validarNumero’ was here
bool validarNumero(char numero[])
^
In file included from listaMaterias.h:5:0,
from menu.c:5:
validacion.h:33:6: error: redefinition of ‘validarLetras’
bool validarLetras(char nombre[])
^
In file included from usario.h:5:0,
from menu.c:4:
validacion.h:33:6: note: previous definition of ‘validarLetras’ was here
bool validarLetras(char nombre[])
^
In file included from listaMaterias.h:5:0,
from menu.c:5:
validacion.h:54:6: error: redefinition of ‘validarFecha’
bool validarFecha(char dia[], char mes[], char ano[])
^
In file included from usario.h:5:0,
from menu.c:4:
validacion.h:54:6: note: previous definition of ‘validarFecha’ was here
bool validarFecha(char dia[], char mes[], char ano[])
These are the mistakes that come to me.
This is the library "listaMaterias.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "validacion.h"
struct actividades
{
char tipoDeActividad[22];
char diaDeLaSemana[12];
char horaDeIncio[8];
char horaDeFin[8];
char salon[10];
};
struct materias
{
char nombre[30];
char profesor[30];
char tipoDeMateria[20];
char horasSemanales[10];
struct actividades *actividad;
struct fechasEspeciales *fechas;
struct materias *siguiente;
};
typedef struct materias _nodoMaterias;
typedef struct fechasEspeciales _nodoFechasEspeciales;
_nodoMaterias *crearListaMaterias(_nodoMaterias *apuntador);
bool listaVacia(_nodoMaterias *apuntador);
_nodoMaterias *insetarEnListaMaterias(_nodoMaterias *apuntador);
void imprimirLista (_nodoMaterias *apuntador);
_nodoMaterias *crearNodoMaterias(char nombre[], char profesor[], char tipoDeMateria[], char horasSemanales[]);
void datosAlumno();
_nodoMaterias *eliminarMateria(_nodoMaterias *apuntador);
bool buscarMateria(char nombre[], _nodoMaterias *apuntador);
_nodoMaterias *modificarMateria(_nodoMaterias *apuntador);
//AQUI SE CREA LISTA Y SE PONE PARA QUE APUNTE A NULL
_nodoMaterias *crearListaMaterias(_nodoMaterias *apuntador)
{
return (apuntador = NULL);
}
//ESTA FUNCION VERIFICA SI LA LISTA ESTA VACIA
bool listaVacia(_nodoMaterias *apuntador)
{
if (apuntador == NULL)
return (true); //SI SALE EL TRUE SIGNIFICA QUE LA LISTA ESTA VACIA
else
return (false);//SI SALE EL FALSE SIGNIFICA QUE LA LISTA NO ESTA VACIA
}
//AQUI SE CREA EL NUEVO NODO DE LA LISTA
_nodoMaterias *crearNodoMaterias(char nombre[], char profesor[], char tipoDeMateria[], char horasSemanales[])
{
_nodoMaterias *registroNuevo;
registroNuevo = (_nodoMaterias *) malloc(sizeof(_nodoMaterias));
printf("\n----NUEVA MATERIA----\n");
printf("NOMBRE: ");
fflush(stdin);
scanf("%s",nombre);
while(!validarLetras(nombre))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s",nombre);
/*while(!buscarMateria())*/
}
printf("PROFESOR: ");
fflush(stdin);
scanf("%s",profesor);
while(!validarLetras(profesor))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nPROFESOR: ");
fflush(stdin);
scanf("%s",profesor);
}
printf("TIPO DE MATERIA: ");
fflush(stdin);
scanf("%s",tipoDeMateria);
while(!validarLetras(tipoDeMateria))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS");
printf("\nTIPO DE MATERIA: ");
fflush(stdin);
scanf("%s",tipoDeMateria);
}
printf("HORAS SEMANALES: ");
fflush(stdin);
scanf("%s",horasSemanales);
while(!validarNumero(horasSemanales))
{
printf("\nPOR FAVOR SOLO ESCRIBA NUMEROS");
printf("\nHORAS SEMANALES: ");
fflush(stdin);
scanf("%s",horasSemanales);
}
fflush(stdin);
strcpy(registroNuevo->nombre, nombre);
strcpy(registroNuevo->profesor, profesor);
strcpy(registroNuevo->tipoDeMateria, tipoDeMateria);
strcpy(registroNuevo->horasSemanales, horasSemanales);
registroNuevo->siguiente = NULL;
return registroNuevo;
}
//AQUI SE INSERTA EL NODO EN LA LISTA LUGEO DE SER CREADO POR LA FUNCION crearNodo
_nodoMaterias *insetarEnListaMaterias(_nodoMaterias *apuntador)
{
_nodoMaterias *registroNuevo, *apuntadorAuxiliar;
char respuesta,ch;
char nombre[30];
char profesor[30];
char tipoDeMateria[20];
char horasSemanales[10];
//ESTE CICLO SE ENCARGA DE QUE SE REPITA EL PORCESO PARA PODER INGRESAR MATERIAS HASTA QUE EL USUARIO DECIDA
do
{
registroNuevo=crearNodoMaterias(nombre, profesor, tipoDeMateria, horasSemanales);
if (listaVacia(apuntador))
apuntador = registroNuevo;
else
{
apuntadorAuxiliar = apuntador;
while (apuntadorAuxiliar->siguiente != NULL)
apuntadorAuxiliar = apuntadorAuxiliar->siguiente;
apuntadorAuxiliar->siguiente = registroNuevo;
}
printf("\nPARA INGRESAR OTRA MATERIA MARQUE... 1");
printf("\nPARA SALIR MARQUE... '0'\n");
while((ch = getchar()) != EOF && ch != '\n');
scanf("%c", &respuesta);
fflush(stdin);
printf("RESPUESTA = %c", respuesta);
}while (respuesta == '1');
return apuntador;
}
//TENGO QUE RIVAR BIEN LA FUNCION DE eliminarMateria PARA VER PQ NO ME ELIMINA LAS MATERIAS
_nodoMaterias *eliminarMateria(_nodoMaterias *apuntador)
{
char materia[20];
printf("\nQUE MATERIA DESEA ELIMINAR: ");
scanf("%s",materia);
fflush(stdin);
//INTENTO DE BORRAR NODO 1
if (!listaVacia(apuntador))
{
_nodoMaterias *borrarAuxiliar;
_nodoMaterias *anterior = NULL;
while (apuntador != NULL)
{
/*anterior = borrarAuxiliar;
borrarAuxiliar = borrarAuxiliar->siguiente;*/
if (strcmp(apuntador->nombre, materia) == 0)
{
anterior->siguiente = apuntador->siguiente;
borrarAuxiliar = apuntador;
apuntador = apuntador->siguiente;
free(borrarAuxiliar);
}
else
{
anterior = apuntador;
apuntador = apuntador->siguiente;
}
}
/*
if (borrarAuxiliar == NULL)
{
printf("\nNODO NO ENCONTRADO");
}else if (anterior == NULL)
{
apuntador = apuntador->siguiente;
free(borrarAuxiliar);
} else
{
anterior->siguiente = borrarAuxiliar->siguiente;
free(borrarAuxiliar);
}*/
}
return apuntador;
}
_nodoMaterias *modificarMateria(_nodoMaterias *apuntador)
{
char materia[20];
printf("\nQUE MATERIA DESEA MODIFICAR: ");
scanf("%s",materia);
fflush(stdin);
if (!listaVacia(apuntador))
{
_nodoMaterias *apuntadorAuxiliar;
apuntadorAuxiliar = apuntador;
while (apuntadorAuxiliar != NULL)
{
if (apuntadorAuxiliar != NULL && strcmp(apuntadorAuxiliar->nombre, materia) == 0)
{
char nombre[30];
char profesor[30];
char tipoDeMateria[20];
char horasSemanales[10];
printf("\nINGRESE LOS NUEVOS DATOS DE LA MATERIA");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s",nombre);
while(!validarLetras(nombre))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s",nombre);
}
printf("PROFESOR: ");
fflush(stdin);
scanf("%s",profesor);
while(!validarLetras(profesor))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nPROFESOR: ");
fflush(stdin);
scanf("%s",profesor);
}
printf("TIPO DE MATERIA: ");
fflush(stdin);
scanf("%s",tipoDeMateria);
while(!validarLetras(tipoDeMateria))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS");
printf("\nTIPO DE MATERIA: ");
fflush(stdin);
scanf("%s",tipoDeMateria);
}
printf("HORAS SEMANALES: ");
fflush(stdin);
scanf("%s",horasSemanales);
while(!validarNumero(horasSemanales))
{
printf("\nPOR FAVOR SOLO ESCRIBA NUMEROS");
printf("\nHORAS SEMANALES: ");
fflush(stdin);
scanf("%s",horasSemanales);
}
fflush(stdin);
strcpy(apuntadorAuxiliar->nombre, nombre);
strcpy(apuntadorAuxiliar->profesor, profesor);
strcpy(apuntadorAuxiliar->tipoDeMateria, tipoDeMateria);
strcpy(apuntadorAuxiliar->horasSemanales, horasSemanales);
apuntadorAuxiliar->siguiente = NULL;
}
apuntadorAuxiliar = apuntadorAuxiliar->siguiente;
}
}
else
printf("\nLA LISTA ESTA VACIA");
return apuntador;
}
//IMPRIMIR LOS NODOS DE LA LISTA
void imprimirLista (_nodoMaterias *apuntador)
{
_nodoMaterias *apuntadorAuxiliar;
apuntadorAuxiliar = apuntador;
if (apuntadorAuxiliar == NULL)
printf("NO HAY ELEMENTOS EN LA LISTA \n");
else
{
while(apuntadorAuxiliar != NULL)
{
printf(" \n------------MATERIAS-------------- ");
printf("\nNOMBRE: %s \n", apuntadorAuxiliar->nombre);
printf("\nPROFESOR: %s \n", apuntadorAuxiliar->profesor);
printf("\nTIPO DE MATERIA: %s \n", apuntadorAuxiliar->tipoDeMateria);
printf("\nHORAS SEMANALES: %s \n", apuntadorAuxiliar->horasSemanales);
apuntadorAuxiliar = apuntadorAuxiliar->siguiente;
}
}
return;
}
//ESTA FUNCION LE PERMITE SABER AL USUARIO LAS MATERIAS QUE INSCRIBIO
void imprimirListaDeMaterias(_nodoMaterias *apuntador)
{
int contador;
_nodoMaterias *apuntadorAuxiliar;
apuntadorAuxiliar = apuntador;
if (apuntadorAuxiliar == NULL)
printf("NO HAY ELEMENTOS EN LA LISTA\n");
else
{
contador = 0;
printf("\nLISTA DE MATERIAS REGISTRADAS\n"); //AQUI VAN APARECIENDO LAS MATERIAS EN ORDEN ASI EL USARIO SABE CUALES DEBE SELCCIONAR
while(apuntadorAuxiliar != NULL)
{
contador++;
printf("%d", contador);printf(".- %s \n", apuntadorAuxiliar->nombre);
apuntadorAuxiliar = apuntadorAuxiliar->siguiente;
}
}
return;
}
bool buscarMateria(char materia[], _nodoMaterias *apuntador)
{
_nodoMaterias *apuntadorAuxiliar;
apuntadorAuxiliar = apuntador;
while (apuntadorAuxiliar != NULL)
{
if (strcmp(apuntadorAuxiliar->nombre, materia) == 0)
{
break;
}
apuntadorAuxiliar = apuntadorAuxiliar->siguiente;
}
if (apuntadorAuxiliar == NULL)
return true;
else
return false;
}
This is the library "usuario.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "validacion.h"
void datosAlumno(char nombre[], char apellido[], char cedula[], char telefono[], char carrera[]);
void datosAlumno(char nombre[], char apellido[], char cedula[], char telefono[], char carrera[])
{
printf("\n INTRODUZCA EL NOMBRE DEL ALUMNO: \n");
scanf("%s", nombre);
while(!validarLetras(nombre))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s", nombre);
}
printf("\n INTRODUZCA EL APELLIDO DEL ALUMNO: \n");
fflush(stdin);
scanf("%s", apellido);
while(!validarLetras(apellido))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nAPELLIDO: ");
fflush(stdin);
scanf("%s", apellido);
}
printf("\n INTRODUZCA LA CEDULA DEL ALUMNO: \n");
fflush(stdin);
scanf("%s", cedula);
while(!validarNumero(cedula))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s", cedula);
}
printf("\n INTRODUZCA EL TELEFONO DEL ALUMNO: \n");
fflush(stdin);
scanf("%s", telefono);
while(!validarNumero(telefono))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s", telefono);
}
printf("\n INTRODUZCA LA CARRERA DEL ALUMNO: \n");
fflush(stdin);
scanf("%s", carrera);
while(!validarLetras(carrera))
{
printf("\nPOR FAVOR SOLO ESCRIBA LETRAS ");
printf("\nNOMBRE: ");
fflush(stdin);
scanf("%s", carrera);
}
fflush(stdin);
system("clear");
printf("\n%s\n", nombre);
printf("\n%s\n", apellido);
printf("\n%s\n", cedula);
printf("\n%s\n", telefono);
printf("\n%s\n", carrera);
getchar();
}
This is the library "validacion.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <ctype.h>
#include <stdbool.h>
bool validarNumero(char numero[50]);
bool validarLetras(char nombre[50]);
bool validarFecha(char dia[], char mes[], char ano[]);
bool validarNumero(char numero[])
{
int i = 0, j;
j = strlen(numero);
while (i < j)
{
if (isdigit(numero[i]) != 0)
{
i++;
}
else
{
return false;
}
}
return true;
}
bool validarLetras(char nombre[])
{
int i = 0, j;
j = strlen(nombre);
while (i < j)
{
if (isalpha(nombre[i]) != 0)
{
i++;
}
else
{
return false;
}
}
return true;
}
bool validarFecha(char dia[], char mes[], char ano[])
{
int month, day, year;
day = atoi(dia);
month = atoi(mes);
year = atoi(ano);
//Si el mes ingresado es Febrero, el año no es bisiesto y el día es mayor a 28 o menor o igual a cero
if((month == 2) && !((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) && ((day > 28) || (day <= 0)))
{
printf("\n\nFecha incorrecta: Este mes solo tiene 28 dias");
return false;
}
//Si el mes ingresado es Febrero, el año es bisiesto y el día es mayor a 29 o menor o igual a cero
else if((month == 2) && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) && ((day > 29) || (day <= 0)))
{
printf("\n\nFecha incorrecta: Este mes solo tiene 29 dias");
return false;
}
//Si el mes es distinto a Febrero (cualquiera de los demás meses que tengan 31 días) y el día es mayor a 31 o menor o igual a cero
else if(((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) && ((day > 31) || (day <= 0)))
{
printf("\n\nFecha incorrecta: Este mes solo tiene 31 dias");
return false;
}
//Si el mes es distinto a Febrero (cualquiera de los demás meses que tengan 30 días) y el día es mayor a 30 o menor o igual a cero
else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day > 30) || (day <= 0)))
{
printf("\n\nFecha incorrecta: Este mes solo tiene 30 dias");
return false;
}
//Si el mes es mayor a 12 o menor o igual a cero
else if((month > 12) || (month <= 0))
{
printf("\n\nFecha incorrecta: El año solo tiene 12 meses");
return false;
}
return true;
}