我开始学习C,并希望从命令行输入字符并将它们排序为一个数组,以便行号是ASCII字符编号,列是输入字符的索引。我知道这必须通过realloc和malloc动态完成,但我不知道如何对其进行编码。有人可以帮我解决这个问题吗?Realloc二维数组
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#define totalASCII 256
int
main(int argc, char **argv) {
int locat;
char current;
int **dRow=NULL;
dRow = malloc(totalASCII*sizeof(*dRow));
for(locat=0;scanf("%c", ¤t)==1;locat++) {
/* I don't know what to put here */
}
return 1;
}
** dRow是指向指针的指针而不是指向数组的指针,因此分配内存并访问它将导致分段错误 – Omkant