【发布时间】:2016-04-15 14:15:39
【问题描述】:
我正在尝试做一个接收字符串并将它们动态存储到结构中的 C 程序,在传递字符串部分之后,我将展示它们中的大部分是编写的。但是我在编写指向结构指针的指针时遇到了麻烦。我正在尝试做一些类似于我绘制的图像here。
#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;
}
【问题讨论】:
-
谢谢,对于 C 和 C++ 标记感到抱歉
-
“我遇到了麻烦” 在哪里?有错误吗?那是什么?
-
问题不在代码上,问题是我没有成功构建这个系统。
-
SO 的存在是为了帮助解决特定问题,而不是为您实施它们。你在什么方面没有成功?这个程序在编译时做了什么?你想让它做什么呢?