整个程序调试时没问题,为啥一执行完我标记的那一句就报错了呢
程序代码:#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
#define falsse 0
#define true 1
#define capacity 50
#define INCR 2
int main(void)
{
char *yanyu = NULL;
char *temp = NULL;
int count = 0;
int num = 0;
int flag = false;
char answer = 'n';
do
{
if (count == num)
{
num += INCR;
temp = (char*)malloc(capacity*sizeof(char));
if (yanyu != NULL)
{
for (int i = 0; i < count; i++)
*(temp + i) = *(yanyu + i);
free(yanyu);
}
yanyu = temp;
free(temp);
temp = NULL;
}
printf("请输入几句谚语:\n");
scanf_s("%s", capacity, yanyu + count++); //此句
printf("还想输入更多吗('y' or 'n')\n");
scanf_s(" %c", &answer);
} while (tolower(answer) == 'y');

