Someone please help me, I am new to all this, I am having trouble reading into a
ID: 3625648 • Letter: S
Question
Someone please help me,I am new to all this, I am having trouble reading into a structure. "Store these into 2 two dimensional arrays of structs. (use the same struct for both arrays)" Any idea of how to write this code?
The following is what is need for a complete program. Any help will be nice
Thanks
1. Read in a list of calendar reminders from a file called “reminders.txt” (they will be stored initially as “mm/dd reminder_string”…e.g., “04/19 Exam 2 in ECE 285”). Each reminder will be read in, then the reminders will be arranged and stored two different ways, chronologically and alphabetically. Store these into 2 two dimensional arrays of structs. (use the same struct for both arrays)
reminders.txt:
04/08 Honor's Day-no classes
04/04 HW 5 due
05/02 Final Exam section 2 from 11:30-2 pm
05/03 Final Exam section 1 from 1-10:30 am
04/28 Last day of class!
04/01 Mom's Birthday
04/23 Dad's Birthday
04/19 Chiropractor 3:45
05/31 My brother comes home!
05/27 Baby shower for Court
05/26 Fly home!
06/03 Family Reunion
01/01 New Year's Day
02/14 Valentine's Day
03/17 St Patrick's Day
07/04 4th of July!
11/24 Thanksgiving
12/25 Christmas
10/31 Halloween
10/24 Anniversary
06/01 Cari's Birthday
12/22 Holly's Birthday
10/03 Russ's Birthday
05/06 Janni's Birthday
03/03 Steve's Birthday
05/01 Lori's Birthday
03/11 My Birthday
04/24 Tami's Birthday
12/25 Crissi's Birthday
02/11 Trevor's Birthday
Explanation / Answer
Dear user, Here is the code below:#include <stdio.h> #include <string.h> #include<stdlib.h> void remainder(char x[][50],int length); void dateOrdered(char x[][50],int length); void str(char x[],char y[],int a,int b); int strcom(char x[50],char y[50]); int main(void) { FILE *fp; int i=0; char ch[30][50]; fp = fopen(”reminders.txt”,"r"); if(fp == NULL) { printf("Error occurred in input file"); return 0; } while(fgets(ch[i], 50, fp) >0) i++; fclose(fp); dateOrdered(ch,i); remainder(ch,i); return 0; } }
void remainder(char x[][50],int length) { FILE* ft; int i,j; char tmp[50]; ft= fopen("List.txt","w"); fprintf(ft,"reminder date "); for(i=0;i<length-1;i++) for(j=i;j<length;j++) if (strcom(x[i],x[j])>0) { strcpy(tmp,x[i]); strcpy(x[i],x[j]); strcpy(x[j],tmp); } for(i=0;i<length;i++) { str(x[i],tmp,8,0); fprintf(ft,"%s ",tmp); str(x[i],tmp,0,8); fprintf(ft,"%s ",tmp); } fclose(ft); } }
void dateOrdered(char x[][50],int length) { FILE* ft; int i,j; char tmp[50]; ft= fopen("Dates.txt","w"); fprintf(ft,"date reminder "); for(i=0;i<length-1;i++) for(j=i;j<length;j++) if (strcmp(x[i],x[j])>0) { strcpy(tmp,x[i]); strcpy(x[i],x[j]); strcpy(x[j],tmp); } for(i=0;i<length;i++) fprintf(ft,"%s",x[i]); fprintf(ft," "); fclose(ft); }
void str(char x[],char y[],int a,int b) {
int i,j=0; if(a<b) {
for(i=a;i<b;i++) y[i]=x[i];
y[i]=''; } else { for(i=a;x[i]!='';i++) y[j++]=x[i]; y[j-1]=''; } } int strcom(char x[50],char y[50]) { int i; for( i = 6; i < 61; ++i) { if(x[i] < y[i]) return -1; else
if(x[i] > y[i]) return 1; else
if(x[i]==''&&y[i]=='') return 0; else
if(x[i]=='') return -1; } return 0; } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.