我想要做的是讀取一個txt文件並將其存儲在一個char成員的結構中,每個字符都是我的文件。將txt文件的每個字符存儲到數組中
這裏是我的代碼:
typedef struct charClass {
char simbolo;
int freq;
} charClass;
這是主要的顯著部分:
input = fopen("testo1.txt", "r");
fseek(input, 0, SEEK_END); //Mi posiziono alla fine del file
int dim = ftell(input); //Ottengo il puntatore corrente (n char)
fseek(input, 0, SEEK_SET); //Rimetto il puntatore all'inizio del file
char tmpChar;
charClass *car;
car = malloc(dim*sizeof(int));
int i = 0;
while (!feof(input)) {
tmpChar = getc(input);
car[i].simbolo = tmpChar;
printf("\n%c", car[i].simbolo);
car[i].freq++;
i++;
}
墜毀。
我嘗試在網上搜索,但沒有找到答案。
我試過也使用fscanf和strcpy,但我無法得到它的工作。
謝謝。