Regarding pointers to struct.

This is a discussion on Regarding pointers to struct. within the C Programming forums, part of the General Programming Boards category; Hi, I was instructed to define the following structs: Code: typedef struct driver{ char name[101]; int priority; struct driver* next; ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    122

    Regarding pointers to struct.

    Hi,
    I was instructed to define the following structs:
    Code:
    typedef struct driver{
        char name[101];
        int priority;
        struct driver* next;
    }Driver;
    
    
    typedef struct taxiSystem{
        Driver * driversQueue;
        Order * ordersQueue;
        int numOrder;
    }TaxiSystem;
    And would now like to use the following function to determine whether a specific driver exists in the queue:
    Code:
    int addDriver(TaxiSystem * system, char * name, int priority)
    {
        int i = 0, j = 0;
        if (name[j] == '\0') return 0;
        return (system->driversQueue->name[i++] == name[j++]) ? addDriver(system, name, priority) : 0;
        
    }
    I realise the function is not programmed correctly. My question is simple - I am not very familiar with structs and the logic involved in handling them, ergo I am not quite certain how to access the string name in Drive. Do I need to use the pointer next (in Driver) for that? I'd appreciate some guidance.
    Last edited by peripatein; 06-06-2013 at 06:05 AM.

  2. #2
    Registered User migf1's Avatar
    Join Date
    May 2013
    Location
    Athens, Greece
    Posts
    235
    Quote Originally Posted by peripatein View Post
    ...
    My question is simple - I am not very familiar with structs and the logic involved in handling them, ergo I am not quite certain how to access the string name in Drive. Do I need to use the pointer next (in Driver) for that? I'd appreciate some guidance.
    Hi, you might want to have a look at this post hoping it will help you understand how to handle structs and their fields (member-variables).

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Don't call your parameter "system" because that's the name of a standard library function.

    It also looks like you need to (re)read how linked lists work.

    Bye, Andreas

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,283
    As of now, your code seems to be scanning two different char arrays to see if their respective elements are equal or not (the 14th element of one equals the 14th of the other).

    You first need to actually build your queue of drivers first and then begin searching through that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 06:19 AM
  2. Want help using struct pointers
    By burkoJames in forum C Programming
    Replies: 2
    Last Post: 05-13-2010, 11:59 PM
  3. Struct as pointers
    By wirefree101 in forum C Programming
    Replies: 8
    Last Post: 12-03-2009, 02:48 PM
  4. pointers to struct - help please
    By seminolas in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 01:03 AM
  5. Assigning pointers from pointers in struct.
    By Brian in forum C Programming
    Replies: 2
    Last Post: 10-18-2003, 05:30 AM

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