Итак, мое задание состоит в том, чтобы брать буквы (6 на строку) текстового файла, сохранять его в связанных списках, а затем распечатывать информацию о конкретной «умирающей» (в данном случае) - каждой группе из 6 буквы.Связанный список не печатает? C
У меня есть данные, чтобы читать правильно (я думаю) в функции readData
, но я не уверен, что этот связанный список будет передан правильно. Когда я пытаюсь распечатать связанный список в main
(строки ~ 40-41), я ничего не получаю. Я передаю свою функцию неправильно readData
?
Вот мой код:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LENGTH 80
struct boggleDataNode{
char data[3];
struct boggleDataNode *nextData;
};
struct boggleDieSideNode{
char dieSideData[3];
struct boggleDieSideNode *nextSide;
};
void readData(struct boggleDataNode *temp);
void printData(struct boggleDataNode *temp);
int main(){
int counter = 0;
struct boggleDataNode *head;
struct boggleDieSideNode *head1;
struct boggleDataNode *temp;
head = NULL;
head1 = NULL;
temp = head;
printf("test\n\n");
readData(&temp);
// printData(temp);
while(counter = 0, counter<100, counter++)
printf("%s ", temp->data[counter]);
system("pause");
return 0;
}
void readData(struct boggleDataNode *temp){
//initializing variables including
//opening the input file
FILE *input = fopen("BoggleData.txt","r");
char data[96] ={};
struct boggleDataNode *new;
int counter =0;
temp = new;
//error checking that the file opened
if (input == NULL){
fprintf(stderr, "Can't open input file!\n");
exit(1);
}
new = (struct boggleDataNode *)malloc(sizeof(struct boggleDataNode));
while(fscanf(input, "%s", data) != EOF){
printf("%s ", data);
strcpy(temp->data, data);
printf("Data number %d %s \n",counter,temp->data);
temp->nextData = NULL;
counter++;
}
}
Я не вижу, где вы выполняете итерацию через связанный список в 'main' - довольно уверен, что должен быть какой-то' while (temp-> next! = NULL) {temp = temp-> next; } ' –
@ M.Shaw здесь, где я пытался:' while (counter = 0, counter <100, counter ++) printf ("% s", temp-> data [counter]); ' – bravesaint
Вы просто печатаете' temp-> data [0] ',' temp-> data [1] '...' temp-> data [99] 'there; Я не вижу, где вы переходите к следующему узлу связанного списка. –