-3
私は周期表を持つファイルを取得し、それを関数readfile
に入れてファイルを読みます。しかし、table1
を印刷すると、(null)0
が印刷されます。どうして?なぜ私は 'c'でヌルを出力するのですか
#define SIZE 200
void readfile(FILE *fp1, char ***table1, int ***graph) {
int counter = 0;
int i;
char table[SIZE];
if (fp1 == NULL) {
printf("The file is incorrect\n");
exit(EXIT_FAILURE);
}
while ((fgets(table, SIZE, fp1)) != NULL) {
counter++;
}
(*table1) = (char **)malloc(counter);
(*graph) = (int**)malloc(counter);
for (i = 0; i < counter; i++) {
(*table1) = (char *)malloc(counter);
(*graph) = (int *)malloc(sizeof(int) * counter);
}
int j = 0;
while ((fgets(table, SIZE, fp1)) != NULL) {
sscanf(table,"%s %d\n", (*table1)[j], &i);
j++;
}
printf("%s%d\n", (*table1)[j]);
}
int main(int argc, char *argb[]) {
FILE *fp1;
fp1 = fopen(argb[1], "r");
char **table1 = NULL;
int **graph = NULL;
readfile(fp1, &table1, &graph);
return 0;
}
あなたは '*'あまりにも多くを持っています。 – pmg
3つ星のプログラマであることは、Cの賛辞ではありません – Olaf
http://c2.com/cgi/wiki?ThreeStarProgrammerまたはhttp://c2.com/cgi/wiki?YouMightBeaThreeStarProgrammerおよびhttp://c2.com/cgi/wiki?ThreeStarProgrammerExamples – pmg