显示一个月的提醒日期

 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     

 

转载于:https://www.cnblogs.com/joyclub/p/4425136.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值