Sha*_*ars 2 c linked-list dynamic-arrays
基本上我必须在链表中存储单词,每个字符都有自己的节点.我对嵌套结构感到困惑.我如何进入下一个节点?我知道我这样做完全错了,这就是我要问的原因.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{
char letter;
}NODE;
typedef struct handle
{
NODE **arr;
}HANDLE;
HANDLE * create();
void insert(handle **, char, int);
int main(int argc, char **argv)
{
FILE *myFile;
HANDLE *table = (HANDLE *)malloc(sizeof(HANDLE));
NODE *linked = (NODE *)malloc(sizeof(NODE));
int counter = 0;
linked = NULL;
table->arr[0] = linked;
char c;
myFile = fopen(argv[argc], "r");
while((c = fgetc(myFile)) != EOF)
{
if(c != '\n')
insert(&table, c, counter);
else
{
counter++;
continue;
}
}
}
void insert(HANDLE **table, char c, int x)
{
(*table)->arr[x]->letter = c; //confused on what to do after this or if this
//is even correct...
}
Run Code Online (Sandbox Code Playgroud)
您有一个单词链接列表,每个单词都是一个链接的字符列表.我对吗?如果是这样,最好使用它们的名称:
typedef struct char_list
{
char letter;
struct char_list * next;
} word_t;
typedef struct word_list
{
word_t * word;
struct word_list_t * next;
} word_list_t;
Run Code Online (Sandbox Code Playgroud)
现在,您可以根据需要填充列表.