我正在試圖做一個接收字符串並將它們動態存儲到結構中的C程序,並且在傳遞字符串部分之後,我將顯示它們的巫婆寫得最多。但我在編寫指向結構指針的指針時遇到了麻煩。我正在嘗試做類似於我繪製的圖像here。指向Struct的指針的指針
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Word{
char* palavra;
int aparicoes;
} ;
struct word createWord(char* str){
struct Word *newWord = malloc(sizeof(struct Word));
assert(newWord != NULL);
newWord->palavra = strdup(str);
newWord->aparicoes = 1;
return newWord;
}
int main(){
char* tempString;
struct Word** lista;
int triggrer = 1;
int i = 0;
while (triggrer == 1)
{
scanf("%s", tempString);
if (strcmp(tempString , "fui") == 0)
triggrer = 0;
else
{
while(*(&lista+i*sizeof(lista)) != NULL){
i++;
}
if(i == 0){
lista = malloc(sizeof(struct Word));
}
else{
lista = (struct Word*) realloc(lista, sizeof(struct Word) + i*sizeof(struct Word));
}
}
}
return 0;
}
[德雅vu..repeated ...](http://meta.stackoverflow.com/q/318618/2173917) –
謝謝,對不起,C和C++標籤 –
「我有麻煩「在哪裏?有錯誤嗎?它以前如何? –