|  | 
 
| 
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  复制代码#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define N 50
#define DAYS 31
int read_line(char s[]);
int reminder(char s[][N]);
int main(void){
        char s[DAYS][N] = {'\0'};
        int day;
        while (true){
                printf("day and remind: ");
                scanf("%d", &day);
                if (day < 1 || day > DAYS){
                        reminder(s);
                        break;
                }
                else
                        read_line(s[day-1]);
        }
        return 0;
}
int read_line(char s[]){
        char str[N];
        char ch;
        int i = 0;
        while ((ch = getchar()) != '\n')
                str[i++] = ch;
        str[i] = '\0';
        strcat(s, str); 
        return 0; 
}
int reminder(char s[][N]){
        for (int i = 0; i < DAYS; i++)
                if (s[i][0] != '\0')
                        printf("%d: %s\n", i+1, s[i]);
        return 0;
}
 运行的结果如下图所示,我只是让它在第二次输入相同日期的备忘事时拼接在对应的字符串后面,可是打印输出中间为什么有个空格,这是什么情况???
 
 | 
 |