#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdbool.h>#define STR_LEN 100int main(){ size_t si = 5; size_t i = 0; int j = 0; char A[STR_LEN]; char *a = NULL; char *pa = NULL; double value = 0; double V = 0; char **pA = calloc(si,sizeof(char*)); if(!pA) { printf("内存不足(1),不能为pA分配内存!\n"); return 1; } while(true) { fgets(A,STR_LEN,stdin); if(A[0] == '\n') break; if(i == si) { si += si; pA = realloc(pA,si); if(!pA) { printf("内存不足(2) ,不能为pA分配内存!\n"); return 2; } } pA[i] = malloc(strlen(A)+1); if(!pA) { printf("内存不足(3),不能为pA[i]分配内存!\n"); return 3; } strcpy(pA[i++],A); } return 0;}
添加回答
举报
0/150
提交
取消