debug code on C(not C+ or C++)
I try to fix by myself, node part show error.
This program should work for scan 5 ints from the user
Using those 5 ints, it require construct a linked list of 5
elements.
After this, it sould prntf of the list using the PrintList.
#include <stdio.h>
struct Node{
int data;
Node* next;
};
int main(void){
struct Node first = {0, 0};
struct Node* second = {0, 0};
Node third = {0, 0};
struct Node fourth = {0, 0};
struct Node fifth = {0, &first};
int i;
scanf(" %d", &i);
first.data = i;
scanf(" %d", &i);
second.data = i
first.next = &second;
scanf(" %d", &i);
third.data = i;
second.next = third;
scanf(" %d", &i);
data = i;
third.next = &fourth;
scanf(" %d", &i);
fifth.data = i;
fourth->next = &fifth;
PrintList(first);
}
PrintList(struct Node* n){
while(n != 0){
printf("%d ", n.data);
n = n.next;
}
printf("\n");
}
CODE
#include <stdio.h>
struct Node{
int data;
struct Node* next;
};
void PrintList(struct Node* n){
while(n != NULL){
printf("%d ", n->data);
n = n->next;
}
printf("\n");
}
int main(void){
struct Node first = {0, 0};
struct Node second = {0, 0};
struct Node third = {0, 0};
struct Node fourth = {0, 0};
struct Node fifth = {0, 0};
int i;
scanf(" %d", &i);
first.data = i;
scanf(" %d", &i);
second.data = i;
first.next = &second;
scanf(" %d", &i);
third.data = i;
second.next = &third;
scanf(" %d", &i);
fourth.data = i;
third.next = &fourth;
scanf(" %d", &i);
fifth.data = i;
fourth.next = &fifth;
PrintList(&first);
}
Get Answers For Free
Most questions answered within 1 hours.