Thread: Pointer problems with structures

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Question Pointer problems with structures

    I am making a program that needs to make an array of linked list, but I keep getting an error that says dereferencing pointer to incomplete type at the point when I am trying to set value to temp. My code is:
    Code:
    #include <stdio.h>
    #include <stdbool.h>
    
    typedef struct //list node
    {
     char destination;
     struct NODE* next;
    
    }NODE;
    
     typedef struct  //linked list
    {
     char startingPoint;
     struct NODE* first;
    
    }LIST;
    
    void fillStruct(char* fileName,LIST map[]);
    void printList();
    void depthSearch();
    void breadth();
    void topoSort();
    NODE* ListIterator(NODE* start);
    
    void fillStruct(char* fileName,LIST map[]){
    char points[60];
    FILE* fpIn;
    int i=0;
    char readIn=' ';
    int j=0;
    struct NODE* temp;
    
    for(j=0;j<60;j++)
    points[j]=' ';
    
    if((fpIn=fopen(fileName,"r"))!=NULL)
    do{
    
    readIn=getc(fpIn);
    if(readIn!=EOF && readIn>='A')
    points[i++]=readIn;
    
    }while(readIn<'A' && readIn!=EOF);
    
    for(j=0;points[j]!=' ';j+=2){
    if(map[(int)points[j]-65].startingPoint==' ')
    map[(int)points[j]-65].startingPoint=points[j];
    temp->destination=points[j+1];
    temp->next=NULL;
    if(map[(int)points[j]-65].first==NULL)
    map[(int)points[j]-65].first=temp;
    else{
    ListIterator(map[(int)points[j]-65].first)->next=temp;
    //last->next=temp;
    }
    
    }
    I know the structure declarations may look a little weird, but that is how my compiler requires them. Any help on what is wrong with my code will be greatly appreciated.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Temp does not point to anything and has no memory allocated for it.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    At no point do you ever declare something called "struct NODE", so you really shouldn't be trying to keep pointers to that type. You should probably give your node type that name, so that you can use it. (I.e., it should say "struct NODE", not just "struct".)

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    13
    I could have sworn I had tried that but obviously not because it just worked.
    Thanks a bunch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 11:01 AM
  2. More pointer problems :(
    By mike_g in forum C Programming
    Replies: 9
    Last Post: 07-21-2008, 07:28 AM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. Pointer Problems
    By tbarsness in forum C Programming
    Replies: 2
    Last Post: 11-09-2006, 05:36 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM