69,368
社区成员
发帖
与我相关
我的任务
分享
char* name[4] = { "aaa", "bbb", "ccc", "ddd" };
name[0][0] = 'x'; // error
#define MAXN 10000 //最多字符串数
#define MAXLEN 128 //每个字符串包含最多字符数127+1个字符串末尾标志'\0'
static STRs[MAXN][MAXLEN];
char s[N][MAX];
char *s[N];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* const argv[]) { //动态载入内存
FILE *fpt;
char line[100];
char* *str_table = NULL;
int size = 0;
int i = 0;
int j;
fpt=fopen("temp.txt","r");
if(fpt==NULL)
{
printf("error");
exit(1);
}
for ( ; fscanf(fpt,"%s",line)!=EOF; ++ i) {
str_table = realloc(str_table, (++ size) * sizeof(char*));
str_table[size - 1] = strdup(line);
}
for (j = 0 ; j< i; ++ j) {
printf("str_table[%d]:%s\n", j, str_table[j]);
free(str_table[j]);
}
free(str_table);
return 0;
}