Thread: List

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    29

    List

    Why can't I add anything to either keylist or locklist?Here's my code,


    Code:
    #include <stdio.h>
    #include <malloc.h>
    #include <string.h>
    #include "key.h"
    #include "lock.h"
    #include "list.h"
    /*Function prototypes*/
    /*main*/ 
    int main(void)
    { 
     FILE * input = fopen("keys.txt" , "r");
     FILE * input = fopen("locks.txt" , "r");
     Key * inKey;
     Key * outKey;
     Lock * inLock;
     Lock * outLock;
     List * keyList = lst_new();
     List * lockList = lst_new();
     int numberofKeys;
     int i;
     fscanf(input, "d\n", &numberofKeys);
     for(i = 0; i < numberofKeys;  i++)
       {
        inKey = ky_read(input);
        lst_add(keyList, inKey);
       }
     printf("No. of keys addded to list = %d\n\n", lst_size(keyList));
     for(outKey = (Key*)lst_first(keyList);
    					       outKey != NULL;
    							    outKey = (Key *)lst_next(keyList))
     {  
      printf("%d %s\n" , ky_getId(outKey), ky_getCode(outKey));
     }
     int numberofLocks;
     int i;
     fscanf(input, "d\n", &numberofLocks);
     for(i = 0; i < numberofLocks;  i++)
       {
        inLock = lc_read(input);
        lst_add(lockList, inLock);
       }
     printf("No. of locks addded to list = %d\n\n", lst_size(lockList));
     for(outLock = (Lock*)lst_first(lockList);
    					       outLock != NULL;
    							    outLock = (Lock *)lst_next(lockList))
     {  
     printf("%d %s\n" , lc_getId(outLock), lc_getCode(outLock));
     }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are we just supposed to guess about what all those functions really do? Ok, if I must...

    I guess that you need a pointer to a pointer, and not just a pointer.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Obviously the problem is inside lst_add or lst_first etc. Unit testing would have picked that up.
    We can't help you without seeing the code for it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM