该代码在DEV-c++上已通过,但在VS上无法运行,要求加_s,但参数不会确定,求帮助
代码如下:
//remind.c
/* Prints a one-month reminder list */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_REMIND 50 //maximum number of reminders
#define MSG_LEN 60 //max length of reminder message
int read_line(char str[], int n);
int main(void)
{
char reminders[MAX_REMIND][MSG_LEN + 3];
char day_str[3], msg_str[MSG_LEN + 1];
int day, i, j, num_remind = 0;
for (;;) {
if (num_remind == MAX_REMIND) {
printf("-- No space left --\n");
break;
}
printf("Enter day and reminders: ");
scanf_s("%2d", &day);
if (day == 0)
break;
sprintf(day_str, "%2d", day);
read_line(msg_str, MSG_LEN);
for (i = 0; i < num_remind; i++)
if (strcmp(day_str, reminders[i]) < 0)
break;
for (j = num_remind; j > i; j--)
strcpy(reminders[j], reminders[j - 1]);
strcpy(reminders[i], day_str);
strcat(reminders[i], msg_str);
num_remind++;
}
printf("\nDay reminder\n");
for (i = 0; i < num_remind; i++)
printf(" %s\n", reminders[i]);
system("PAUSE");
}
int read_line(char str[], int n)
{
int ch, i = 0;
while ((ch = getchar()) != '\n')
if (i < n)
str[i++] = ch;
str[i] = '\0';
return i;
}