Question

debug code on C(not C+ or C++) I try to fix by myself, node part show...

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");
}

Homework Answers

Answer #1

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);

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the...
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0,...
For the following code in C, I want a function that can find "america" from the...
For the following code in C, I want a function that can find "america" from the char array, and print "america is on the list" else "america is not on the list" (Is case sensitive). I also want a function to free the memory at the end of the program. #include <stdio.h> #include <stdlib.h> struct Node { void *data; struct Node *next; }; struct List { struct Node *head; }; static inline void initialize(struct List *list) { list->head = 0;...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
q7.3 Fix the errors in the code (in C) //This program uses a function called CharacterScan...
q7.3 Fix the errors in the code (in C) //This program uses a function called CharacterScan to read a char from the user //The function must take an int pointer as a parameter //The program should print the char and ascii code for each character the user enters //The program should only exit whe nthe user enters escape #include <stdio.h> char CharacterScan(int*); int main(void){ while(1){ int aCode; int* iPtr; char* c = CharacterScan(iPtr); if(aCode) break; else printf("%c is ASCII code...
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input....
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input. The first integer indicates the number of values that will follow. Read that many values, and return their sum, ignoring any additional values that may follow. However, if there are fewer integers than specified in the input, print "Error" and terminate. Hint: int n, success; ... success = scanf("%d", &n); // FIRST INTEGER INPUT reads an integer from stdin, returning 1 if the integer...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
C++, I am not able to get this program to function correctly, ie not launching at...
C++, I am not able to get this program to function correctly, ie not launching at all #include <iostream> #include <stdio.h> int insert(int num, int location) { int parentnode; while (location > 0) { parentnode =(location - 1)/2; if (num <= array[parentnode]) { array[location] = num; return; } array[location] = array[parentnode]; location = parentnode; } array[0] = num; } int array[100], n; using namespace std; main() { int choice, num; n = 0; while(1) { printf("1.Insert the element \n"); printf("2.Delete...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT