i am having problems in this code, it intends to read an array of structs, with size given by the user, structs that consist of 2 strings, 1 enum and 2 ints. after that read other struct, that consist of 2 ints and one enum, and compare the ints and the enums of this struct with each one of the array. if its equal it prints the two strings. in case is not, it prints "nenhum evento encontrado!"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum mes {janeiro=1,fevereiro,marco,abril,maio,junho,julho,agosto,setembro,outubro,novembro,dezembro};
struct data{
int dias;
enum mes meis;
int ano;
};
struct evento{
char nome [100];
char local [100];
int dia;
enum mes mos;
int anos;
};
void cadastrar_eventos(struct evento agenda[], int n){
int i;
struct evento *p1;
p1=agenda;
for (i=0;i<n;i++){
fgets (p1->nome,100,stdin);
fgets (p1->local,100,stdin);
scanf ("%d",&(p1->dia));
scanf ("%u",&(p1->mos));
scanf ("%d",&(p1->anos));
p1++;
}
}
void imprimir_eventos(struct evento agenda[], struct data d, int n){
int i;
int count;
count=0;
struct evento *p1;
p1=agenda;
for (i=0;i<n;i++){
p1=&agenda[i];
if (d.dias==agenda[i].dia &&
d.meis==agenda[i].mos && d.ano==agenda[i].anos){
printf ("%s %s\n",p1->nome,p1->local);
count++;
}
}
if (count==0){
printf("Nenhum evento encontrado!");
}
}
int main (){
int n;
struct data hor, *p3;
p3=&hor;
scanf ("%d",&n);
struct evento agenda[n];
cadastrar_eventos(agenda,n);
scanf ("%d",&hor.dias);
scanf ("%u",&hor.meis);
scanf ("%d",&hor.ano);
imprimir_eventos (agenda,hor,n);
return 0;
}
this was the code, but after i tried to use it, when i put the values it will not work. i put the first number (size of the array) and the two first strings and it instantly printf something ramdom. for example if i put '1' 'name' and 'event', it gives
nome [Inferior 1 (process 670) exited normally]