Thread: Structure and Linked List User Input Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    This is my attempt at inputting an additional var.

    This is my first try at getting the 6th value inputted. Compiles but crashes after the first 5 values are inputted and displayed.


    PHP Code:

    #include <stdio.h>
    struct Oomba
        
    {
        
    int value;
        
    int value2;
        
    struct Oomba *nextaddr;
        };

    void display(struct Oomba *);
    void display2(struct Oomba *);
    int main()
    {
    struct Oomba *first;
    struct Oomba v1,v2,v3,v4,v5,v6,v7,v8;

    first = &v1;
    v1.nextaddr = &v2;
    v2.nextaddr = &v3;
    v3.nextaddr = &v4;
    v4.nextaddr = &v5;
    v6.nextaddr NULL;



    printf("Please input the value 1\n");
    scanf("%d",&v1.value);
    printf("\n\nPlease input the value 2\n");
    scanf("%d",&v2.value);
    printf("Please input the value 3\n");
    scanf("%d",&v3.value);
    printf("\n\nPlease input the value 4\n");
    scanf("%d",&v4.value);
    printf("\n\nPlease input the value 5\n");
    scanf("%d",&v5.value);

    display(first);

    printf("\n\nPlease input the value 6\n");
    scanf("%d",&v1.value2);
    display2(first);

    return 
    0;

    }

    void display(struct Oomba *contents)
    {
    while (
    contents != NULL)
         {
         
    printf("\n%d",contents->value);
         
    contents contents->nextaddr;
         }
    return;
    }

    void display2(struct Oomba *contents)
    {
    while (
    contents != NULL)
         {
         
    printf("\n%d",contents->value);
         
    contents contents->nextaddr;
         
    printf("\n%d"contents ->value2);
         }
    return;


  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Quote Originally Posted by kevndale79
    This is my first try at getting the 6th value inputted. Compiles but crashes after the first 5 values are inputted and displayed.
    Is it ? Or does it just stop ? If it crashes, what error message do you get ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  3. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM