我正在试图做一个接收字符串并将它们动态存储到结构中的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++标签 –
“我有麻烦“在哪里?有错误吗?它以前如何? –