テキストファイルを読み込み、各行をvoid *型のリンクリストのノードに格納しようとしています。 ここにリストのヘッダファイルがあります。タイプのリンクリストvoid *
#ifndef LINKEDL
#define LINKEDL
struct node_s {
void *data;
struct node_s *next;
};
struct node_s *node_create(void*);
struct node_s *list_insert_after(struct node_s*, void*);
struct node_s *list_insert_beginning(struct node_s*, void*);
int list_remove(struct node_s*, struct node_s*);
int list_foreach(struct node_s*, int(*)(void*));
int printstring(void *s);
#endif
すべてのリンクされたリスト機能は完全にテストされているので、どのように使用するかによって問題が発生すると思います。私が達成したいのは、各ノードに1行ずつあり、私が今持っているのは、すべてのノードの最終行です。私はそれがチャーポインターと関係があると思うが、驚くべき突破口なしにすでに2時間を費やしているので、多分誰かが助けることができるだろうか? また、私が使用するリストは、hereのように変更されたリストです。
if (file == NULL)
{
perror("Error opening file");
}
else
{
char mystring[SIZE];
char temp[SIZE];
list = node_create((void*)mystring);
current = list;
while (fgets(mystring, SIZE, file) != NULL)
{
strcpy(temp, mystring);
printf("%d\t%s",counter++,temp);
current=list_insert_after(current, (void*)temp);
}
fclose(file);
}
更新日: ありがとうございました。
に
:
をそしてラインを変更この同じ文字列を指しています。新しいノードがポイントするための新しい文字列をmallocする必要があります。 –