Like Tree1Likes
  • 1 Post By whiteflags

Help! No idea where to start on this. Arrays of structs, doubly linked lists.

This is a discussion on Help! No idea where to start on this. Arrays of structs, doubly linked lists. within the C Programming forums, part of the General Programming Boards category; I've posted the assignment. I'm not asking someone to do this for me, just to point me in the right ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    42

    Help! No idea where to start on this. Arrays of structs, doubly linked lists.

    I've posted the assignment. I'm not asking someone to do this for me, just to point me in the right direction.

    I know how to create and manage structures and to a lesser extent arrays of structures, I'm just in the dark about how to connect two arrays of structs to a doubly linked list (which is what I assume the assignment is asking me to do).

    Any and all help is greatly appreciated. The attached file is the assignment.
    Attached Images Attached Images

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    42
    Code:
    //Paul Omans
    #include<stdio.h>
    #include<stdlib.h>
    
    struct directory{
        char circleName[42];
        int startBlock;
    };
    
    struct FAT{
        char name[42];
        char number[42];
        int nextBlock;
        int previousBlock;
    };
    
    int main(){
        struct directory directoryClass[10];
        struct FAT FATClass[100];
    
    
    }
    Here's what I have so far.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Paul Omans View Post
    I'm just in the dark about how to connect two arrays of structs to a doubly linked list (which is what I assume the assignment is asking me to do).
    I don't think you have to connect both arrays to a doubly linked list. Only each "circle" is implemented as a doubly linked list within the FAT array. Your directory array just provides the starting index for each circle list and your FAT array holds all the data.

    I think a good starting point for you is reading each line from the file, parsing it and print out what you should do. This would assure that the reading/parsing part works.

    Then you can tackle each operation (adding, deleting, querying) separately

    Bye, Andreas

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    42
    Code:
    //Paul Omans
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    struct directory{
        char circleName[42];
        int startBlock;
    };
    
    struct FAT{
        char name[42];
        char number[42];
        int nextBlock;
        int previousBlock;
    };
    
    int main(){
        struct directory directoryClass[10];
        struct FAT FATClass[100];
        static const char filename[] = "hw7.data";
        FILE *file = fopen(filename, "r");
        if (file != NULL)
        {
            char line[128];
            while(fgets(line, sizeof line, file)!= NULL)
            {
                int length = strlen(line); int i;
                for(i=0;i<length;i++)
                {
                    //Parse each line into separate words
                }
                fputs(line, stdout);
            }
            fclose(file);
        }
    
    }
    Here's what I have so far. I'm not sure how to parse the line out to separate strings.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Here's what I have so far. I'm not sure how to parse the line out to separate strings.
    Well what are you thinking?

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    42
    I was thinking to split each line into separate strings at each whitespace and put the strings into the two structures. For example, a line could be "Friends Chuck 2326042 a" and I would split it into "Friends", "Chuck", "2326042", "a".

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Quote Originally Posted by Paul Omans View Post
    I was thinking to split each line into separate strings at each whitespace and put the strings into the two structures. For example, a line could be "Friends Chuck 2326042 a" and I would split it into "Friends", "Chuck", "2326042", "a".
    Well that is a start. I'd do it. Don't worry about it being optimal or anything like that. Implementing your ideas is a better learning experience than hand-holding. If you don't learn how to solve a problem you can't be a programmer, since a lot of software development is getting these kinds of ideas and applying them.

    I'll help you once your idea breaks the program.
    seemaxie likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Doubly Linked Lists!
    By black_stallion in forum C Programming
    Replies: 7
    Last Post: 10-31-2011, 01:48 AM
  2. Doubly linked lists
    By mohanlon in forum C Programming
    Replies: 8
    Last Post: 12-08-2010, 12:01 AM
  3. help with doubly linked lists
    By jjexpress in forum C Programming
    Replies: 4
    Last Post: 12-05-2010, 10:42 AM
  4. Doubly Linked Lists
    By tsut in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2003, 07:53 AM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21