改不动了,坛友们帮我看看我标记的那一句
程序代码:
#define _STDC_WANT_LIB_EXT1_1 #include "stdio.h" #include "string.h" #include "stdlib.h" #define capacity 50 void convert(char*, char str[]); void rtern(char str[]); int main(void) { char *ptr = (char*)malloc(capacity); char buf[capacity] = { NULL }; printf("请输入一串字符:\n"); fgets(ptr, capacity, stdin); convert(ptr, buf); rtern(buf); free(ptr); ptr = NULL; return 0; } void convert(char* p, char word[]) { char delimiters[] = " \" ,;:)( "; char buf[capacity]; char *ptr = NULL; strcpy_s(buf, capacity, p); char *pstr = strtok_s(buf, delimiters, &ptr); //就是下面这句,怎样彻底单元化一个字符串 while (pstr !=NULL) { if (pstr!=NULL) pstr = strtok_s(NULL, delimiters, &ptr); } free(p);//删去free也错 p= NULL; strcpy_s(word, capacity, pstr); printf("%s\n", word); } void rtern(char* q) { printf("%d\n", strlen(q)); }