大佬看看这个代码错误在哪,调试一直错
程序代码:#define _STDC_WANT_LIB_EXT1_1
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define capacity 50
int main(void)
{
char *p = (char*)malloc(capacity);
char delimiters[] = " \" ,;:)( ";
char **temp = NULL;
char **buf = NULL;
char *pstr = NULL;
char *ptr = NULL;
int num = 0;
int add = 0;
int flag = 0;
printf("请输入一串字符:\n");
fgets(p, capacity, stdin);
do{
if (num == add)
{
add += 3;
temp = (char**)malloc(add);
for (int i = 0; i < add; i++)
*(temp + i) = (char*)malloc(capacity);
if (buf)
{
for (int i = 0; i < num; i++)
temp[i] = buf[i];
free(buf);
}
buf = temp;
free(temp);
temp = NULL;
}
if (!flag)
{
pstr = strtok_s(p, delimiters, &ptr);
strcpy_s(*(buf + num++), capacity, pstr);
}
else
strcpy_s(*(buf + num++), capacity, pstr);
flag = 1;
} while ((pstr = strtok_s(NULL, delimiters, &ptr)) != NULL);
for (int i = 0; i < num; i++)
printf("%s", *(buf + i));
free(buf);
buf = NULL;
free(p);
p = NULL;
return 0;
}



