1 #include "stdafx.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #define MAX_REMIND 50
6 #define MSG_LEN 60
7 int read_line(char str[],int n);
8 int main(void)
9 {
10 char reminders[MAX_REMIND][MSG_LEN+3];
11 char day_str[3],msg_str[MSG_LEN+1];
12 int day,i,j,num_remind =0;
13
14 for(;;)
15 {
16 if(num_remind == MAX_REMIND)
17 {
18 printf_s("-- NO space left--\n");
19 break;
20 }
21 printf_s("Enter day and reminder:");
22 scanf_s("%2d",&day);
23 if(day == 0)
24 break;
25 sprintf(day_str,"%2d",day);
26 read_line(msg_str,MSG_LEN);
27 for(i = 0;i < num_remind;i++)
28 if((strcmp(day_str,reminders[i])) < 0)
29 break;
30 for(j = num_remind ; j > i ; j--)
31 strcpy_s(reminders[j],reminders[j-1]);
32 strcpy_s(reminders[i],day_str);
33 strcat_s(reminders[i],msg_str);
34 num_remind++;
35 }
36 printf_s("\nDay Reminder\n");
37 for(i = 0;i < num_remind;i++)
38 {
39 printf_s("%s\n",reminders[i]);
40 }
41 system("pause");
42 return 0;
43 }
44 int read_line(char str[],int n)
45 {
46 int ch , i = 0;
47 while((ch = getchar() != '\n'))
48 {
49 if(i < n)
50 {
51 str[i++] = ch;
52 }
53 }
54 str[i] = '\0';
55 return i;
56 }
57