Thread: Linked List in C

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Linked List in C

    Too many things wrong with it.
    Last edited by incognito; 03-28-2004 at 03:27 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Please help
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Please help
    I'm sure so many people could have viewed and answered your first post in less than one minute...

    Your code is filled with C++isms that cause errors in C. This compiles, but I didn't test it for logic errors:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct Student
    {
      int x;
      struct Student * Next;
    }Student;
    
    int main()
    {
      int Choice;
      int Salir;
      Student* Head;
      Student* Dummy2;
      Student Dummy;
      Dummy2=(Student*)malloc(sizeof (Student) );
      Head=(Student*)malloc(sizeof (Student) );
      Head->Next=0;
      Dummy2->Next=0;
      Choice;
      Salir=0;
    
      for (;;)
      {
    
        printf("Que desea hacer\n");
        printf("1)Insertar Estudiante\n");
        printf("2)Ver Estudiantes\n");
        printf("3) Salir\n");
        scanf("%d",&Choice);
    
        switch (Choice)
        {
        case 1:
          {
    
            printf("Get Student's Age\n");
            scanf("%d",&Dummy.x);
    
            if (Head->Next==0)
            {
              Head=&Dummy;
            }
    
            else  
            {
              Dummy2=Head;
              while(Dummy2->Next!=NULL)
              {
                Dummy2=Dummy2->Next;
              }
              Dummy2->Next=&Dummy;
    
    
              printf("AGe %d",Dummy.x);
    
            }
    
            break;
          }
    
        case 2:
          {
            Student* TempHead;
            TempHead=(Student*)malloc(sizeof (Student) );
            TempHead=Head;
            while (TempHead->Next!=NULL)
            {
              printf("head age %d",TempHead->x);
              TempHead=TempHead->Next;
            }
    
            break;
          }
    
    
        case 3: Salir=1;
          break;
        }
    
        if (Salir)
          break;
    
      }
    
      return 0;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM