printing from an array struct by refrence
I used 6 functions. Three of them (read) are for scanning, and the other
ones are for printing (write).I checked the read funtions works correctlly
and the problem is mainly in one of the write funtions. the problem that I
scan integers from the user,and store them in a array of structers but
when it comes to printing them, i get only the last integers entred
#include<stdio.h>
#include<string.h>
typedef struct
{
char month[20];
int day;
int year;
} date_t;
typedef struct{
int hours;
int minutes;
int seconds;
}time_t;
typedef struct
{
char event[20];
time_t tm;
date_t dt;
}event_t;
int wr_event(const event_t*);
int wr_date(const event_t*);
int wr_time(const event_t*);
int rd_event(event_t*);
int rd_date(event_t*);
int rd_time(event_t*);
int main()
{
int i,j=0,temp=1;
event_t ev[5];
while(temp!=0&&j!=5)
{
rd_event(&ev[j]);
temp=strcmp(ev[j].event,"exit");
j++;
}
if(temp==0)j=j-1;
for(i=0;i<j;i++){
wr_event(&ev[i]);
}
}
int rd_time(event_t *ev)
{
printf("hours->");
scanf("%d",&ev->tm.hours);
printf("minutes->");
scanf("%d",&ev->tm.minutes);
printf("secondes->");
scanf("%d",&ev->tm.seconds);
}
int rd_date(event_t *ev)
{
printf("day-> ");
scanf("%d",&ev->dt.day);
fflush(stdin);
printf("month->");
gets(ev->dt.month);
printf("year->");
scanf("%d",&ev->dt.year);
}
int rd_event(event_t *ev)
{
printf("\nevent name->");
fflush(stdin);
gets(ev->event);
if(strcmp(ev->event,"exit")!=0){
rd_time(&ev);
rd_date(&ev);
}
}
int wr_time(const event_t *ev)
{
printf("this is the time of the event->%d %d
%d\n\n",ev->tm.hours,ev->tm.minutes,ev->tm.seconds);
}
int wr_date(const event_t *ev)
{
printf("this the date of the event-> %d %s
%d\n\n",ev->dt.day,ev->dt.month,ev->dt.year);
}
int wr_event(const event_t *ev)
{
printf("\nthis is your event-> %s\n\n",ev->event);
wr_time(&ev);
wr_date(&ev);
}
No comments:
Post a Comment