私はおそらくまたかなり単純な何かを見逃していますが、ラボで何時間も過ごしたために、ここで何が間違っていたのかを理解できませんでした. リストを作成し、ファイルの終わりまで新しい文字が読み込まれるときに新しいノードを追加することにより、ファイルから読み込まれるすべての文字のリンクされたリストを作成しようとしています。
まず背景について説明します。ノード構造のコードは次のとおりです。
typedef struct node
{
//each node holds a single character
char data;
//pointer to the next node in the list
struct node *next;
}node;
いくつかの printf ステートメントを使用することで、問題をこのコード ブロックのどこかに絞り込むことができました。
FILE *infile = fopen("data.txt", "r");
int c;
int counter = 0;
node *head, *current = NULL;
//Get the count of our original rules and create the list
do{
node *item = new node();
c = fgetc(infile);
if(c == '\n'){
counter ++;
}
printf("From infile: %c \n", c);
item->data = c;
item->next = NULL;
printf("Item data: %c", item->data);
if (head == NULL){
head = current = item;
}
else {
current->next = item;
current = item;
}
}while( c != EOF);
どこにあるのか定かではありませんが、そこにあることは知っています。これがどこで間違っているのかを指摘するために別の目を得ることができれば、私はそれを感謝します.