Thread: Help in dynamic and Linked Lists

  1. #16
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    ok i put the function prototypes outside! and it seem to be running properly for 2 sets of data ONLY :/ not more!
    Code:
    int main()
    {
        Individual I[1];
        menu(I);       
    }
    
    Can you see why you can't put more than two instances of Individual into the array named "I"?

  2. #17
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Gah! The program is full of hidden Windows characters that I'm having trouble getting rid of. Anyone having more success?

  3. #18
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    if i put more it crashes just like it did before!

  4. #19
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    hey i did as you asked and it seems to be working!...btw what type of compiler do you recommend jweoblewski44?
    Code:
    #include <stdio.h>
    
    typedef struct{
            char name[50];
            int age;
            char gender[50];
            int position;
            }ind; //Individual
            
    void input(ind I[], int n);
    void output(ind I[], int n);
    
    void input(ind I[], int n)
    {
         int x;
         for(x=0; x<n; x++)
         {
                  printf("Enter name: ");
                  scanf("%s", I[x].name);
                  printf("Enter age: ");
                  scanf("%d", &I[x].age);
                  printf("Enter gender: ");
                  scanf("%s", I[x].gender);
                  printf("Enter position: ");
                  scanf("%d", &I[x].position);
         }
    }
    
    void output(ind I[], int n)
    {
         int x;
         for(x=0; x<n; x++)
         {
                  printf("NAME: %s\n", I[x].name);
                  printf("AGE: %d\n", I[x].age);
                  printf("GENDER: %s\n", I[x].gender);
                  printf("POSITION: %d\n\n", I[x].position);
         }
    }
    
    int main()
    {
        int n;
        printf("Enter number of registered individuals: ");
        scanf("%d", &n);
        ind I[n];
        int opt;
        do{ 
        printf("1. Add\n2. View\n3. Exit\n\n");
        printf("Option: ");
        scanf("%d", &opt);
        switch(opt)
        {
                   case 1:
                        input(I, n);
                        break;
                        
                   case 2:
                        output(I, n);
                        break;
                        
                   case 3:
                        break;
                        
                   default:
                           printf("INVALID\n\n");
                           break;
        }
        }while(opt!=3);
    }

  5. #20
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Well I recommend you to use Linux instead of Windows. It simplifies the development process if you're not dead tied to Visual Studios, with a very easy-to-use compiler and more text editors to develop in than you could shake a stick at.

    The compiler I use, much like I assume most people here, is gcc. It is a very simple command line tool.

    Disclaimer: I truly enjoy Linux much more than Windows, but as some will undoubtedly be quick to tell you, it is not better. It is just a different method of accomplishing the same task. It's just my preferred method.

    Edit: Kudos for following everyone's advice to the bitter end.

  6. #21
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    i have tried a different approach to the program. im using the stuct method rather than typdef struct! this way i'm not using an array to enter information. And it seems to be writing to the file quite well...so far! However i have a problem with output! How do you read from a file from which you dont know how much data is stored? can you use "EOF"?
    and i tried linux ubuntu but ut seemed to be running slow on my laptop :/ i shall try it again!

  7. #22
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    You can now start working on your linked list

    I use Windows XP, programming on Code::Blocks (which uses the compiler mingw)

    If you wanted to start a new question, it might be a good idea to start a new thread

    [edit]
    I see your new thread - Ignore this post
    [/edit]
    Last edited by Click_here; 02-26-2013 at 11:41 PM.
    Fact - Beethoven wrote his first symphony in C

  8. #23
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Code::Blocks is a good IDE that I also have used before. It works well, except for the debugger (at least in my scenario)! gdb never fails.

    Also, I would recommend Debian over Ubuntu. Ubuntu is just a system built up over Debian and tends to be too "cutting-edge" for me. Debian Squeeze will run well on your laptop, especially if you install a fast desktop environment like XFCE (that is the one I run).
    Last edited by jwroblewski44; 02-27-2013 at 03:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double Linked Dynamic Lists Vs Unrolled Linked Lists
    By lantzvillian in forum C Programming
    Replies: 6
    Last Post: 02-14-2012, 01:07 PM
  2. From Python's Linked Lists to Dynamic Arrays
    By hexbox in forum C Programming
    Replies: 3
    Last Post: 01-26-2005, 03:14 PM
  3. question on linked lists(stack with linked lists)
    By dionys in forum C Programming
    Replies: 1
    Last Post: 06-02-2004, 11:08 AM
  4. Dynamic number of linked lists
    By foniks munkee in forum C Programming
    Replies: 2
    Last Post: 02-24-2002, 09:30 PM
  5. dynamic memory + linked lists
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 02-10-2002, 04:50 PM