Thread: struct member parse error

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    struct member parse error

    Hey guys i get a pass error when i try to access a struct member

    currentItem = CategoryType->headItem;

    im trying to point the currentItem to the head of the item list
    my struct is below.





    Code:
     int loadData(GJCType* menu, char* menuFile, char* submenuFile)
    {
       /*pointer for malloc*/
       CategoryType *newCat, *currentCat, *prevCat ;
       ItemType     *newItem, *currentItem, *prevItem;
       
       
    
       /*declaration of variables*/
       int CountNoLines = 0;
       char temp[LINE_LENGTH];
       char tempf2[LINE_LENGTH];
       
       /* variables for tokenizer for menu file*/
       char *catID;
       char *catType;
       char *catName;
       char *catDescription;
       char *line;
       
       int count;
       
       /* variables for sub menu*/
       char *itemIDPtr;
       char *itemNamePtr;
       char *itemDescriptionPtr;
       char *dollarPtr;
       char *centsPtr;
       
       float dollarInt;
       float centInt;
       
       /* declare file pointers to files*/
       FILE *f1;
       FILE *f2;
       
       
       /* opening the menu and submenu for reading*/
       f1 = fopen(menuFile, "r");
       f2 = fopen(submenuFile, "r");
       
       /* check to see if the filuse exists*/
       if(f1 ==NULL || f2 == NULL)
       {
          /* check whether both files have existed or typed in correctly*/
          if(f1 == NULL && f2 == NULL)
          {
          
             printf("Both files do not exist %s %s\n",menuFile,submenuFile);
          }
          /* check for each file existance*/
          else if (f1 == NULL)
          {
             printf("%s does not exist\n\n",menuFile);
          }
          /* check for each file existance*/
          else if(f2 == NULL)
          {
             printf("%s does not exist\n\n", submenuFile);
    	 
          } 
          printf("EXITING PROGRAM ERROR!\n\n");
          return ERRORCODE; /* cannot proceed*/
       }
       
       /* counts how many fields there are in the file*/
       
       while(fgets(temp, LINE_LENGTH +2, f1)!=NULL)
       {
               
    	   
               currentCat = menu->headCategory;
       
    	   newCat = malloc(sizeof(CategoryType));
    	   
    	   
               if(prevCat == NULL)
    	   {
    	       menu->headCategory = newCat;
    	       
    	   
    	   }
    	  /* else
    	   {
    	       prevCat->nextCategory = newCat;
    	      
    	  */
       
               /* stores the catID but also checks if there
    	   is a duplicate*/
    	    
               catID = strtok(temp, "|");
    	   
    	   /* checking whether it tokenizez*/
    	/*   if(catID == NULL)
    	   {
    	      printf("CatID missing\n");
    	   }*/
    	   strcpy(newCat->categoryID, catID);
    	   
    	   
    	   /*checks for a duplication of the id field*/
    	   if(!checkDuplicationID(menu, catID))
    	   {
    	      return ERRORCODE;
    	   }
               /* gets the second field and tokenizez it*/
    	   catType = strtok(NULL, "|");
    	   newCat->drinkType = catType[0];
    	   
    	    /* checking whether it tokenizez*/
    	   if(catType == NULL)
    	   {
    	      printf("CatType missing\n");
    	   }
    	   
    	   
    	   catName = strtok(NULL, "|");
    	   strcpy(newCat->categoryName, catName);
    	    /* checking whether it tokenizez*/
    	    
    	   if(catName == NULL)
    	   {
    	      printf("CatName missing\n");
    	   }
    	   
    	   
    	   catDescription = strtok(NULL, "\n");
    	   strcpy(newCat->categoryDescription, catDescription);
    	    /* checking whether it tokenizez*/
    	   if(catDescription == NULL)
    	   {
    	      printf("CatDescription missing\n");
    	   }
    	   
    	   /* checks the string length of the field*/
    	   if((strlen(catID) >ID_LEN) ||
    	      (strlen(catType) >MAX_NAME_LEN)  ||
    	      (strlen(catDescription) >MAX_DESC_LEN))
    	      
    	   {	   
    	   
    	      printf("Wrong data format\n\n");
    	      return ERRORCODE;
    	      
    	   }
    	   
    	   
    	   
    	   
    	   /* put the pointer to the start of the list*/
    	   
    	   /*newCat->nextCategory = NULL;
    	    newCat->headItem = NULL;
    	    newCat->numItems = 0;
    	    prevCat = newCat;*/
    	    /*
    	    currentCat = menu->headCategory;
    	    prevCat = NULL;
    	    
    	   
    	    
    	    if(prevCat == NULL)
    	    {
    	       menu->headCategory = newCat;
    	       newCat->nextCategory = currentCat;
    	    
    	    }
    	    else
    	    {
    	       prevCat->nextCategory=newCat;
    	       newCat->nextCategory = currentCat;
    	    }*/
    	    
    	  
    	    
    	   
    	      while(currentCat !=NULL)
    	   {
    	      printf("%s %c %s %s\n", currentCat->categoryID,
    	      currentCat->drinkType,currentCat->categoryName,
    	      currentCat->categoryDescription);
    	      
    	      currentCat = currentCat->nextCategory;
    	   
    	   }
    	  
    	 
    	  
       }  /*end of while loop*/   
          
       while(fgets(tempf2, LINE_LENGTH +2, f1)!=NULL)
       {
               
    	   
               currentItem = CategoryType->headItem;
       
    	   newItem = malloc(sizeof(ItemType));
    	   
    	   
               if(prevItem == NULL)
    	   {
    	     /*  menu->headItem = newItem;*/
    	       
    	   
    	   }
    	 
    	  
    	    
    	  
    	  
    	 
    	  
       }  /*end of while loop*/   
       
       /* close both files after reading*/
       if(fclose(f1)!=0 || fclose(f2)!=0)
       {
          fprintf(stderr, "Error in closing files\n");
       }   
      
    
       return EXIT_SUCCESS;
    }


    Code:
    #ifndef GJC_H
    #define GJC_H
    
    /* System-wide header files. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    /* System-wide constants. */
    #define ID_LEN 5
    #define MIN_NAME_LEN 1
    #define MAX_NAME_LEN 25
    #define MIN_DESC_LEN 1
    #define MAX_DESC_LEN 250
    #define NUM_PRICES 3
    #define HOT 'H'
    #define COLD 'C'
    #define ERRORCODE 1
    #define VALID 0
    #define LINE_LENGTH 500
    #define TOKEN_PRODUCT 4
    
    typedef struct category* CategoryTypePtr;
    typedef struct item* ItemTypePtr;
    
    /* Structure definitions. */
    typedef struct price
    {
       unsigned dollars;
       unsigned cents;
    } PriceType;
    
    typedef struct item
    {
       char itemID[ID_LEN + 1];
       char itemName[MAX_NAME_LEN + 1];
       PriceType prices[NUM_PRICES];
       char itemDescription[MAX_DESC_LEN];
       ItemTypePtr nextItem;
    } ItemType;
    
    typedef struct category
    {
       char categoryID[ID_LEN + 1];
       char categoryName[MAX_NAME_LEN + 1];
       char drinkType;      /* (H)ot or (C)old. */
       char categoryDescription[MAX_DESC_LEN];
       CategoryTypePtr nextCategory;
       ItemTypePtr headItem;
       unsigned numItems;
    } CategoryType;
    
    typedef struct gjc
    {
       CategoryTypePtr headCategory;
       unsigned numCategories;
    } GJCType;
    
    int commandLineArguments(int argc, char* argv[]);
    int countToken(FILE *fp, char* temp, int tokenPerLine);
    #endif

  2. #2
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    currentItem seems to be defined as a pointer to ItemType, which appears to be undefined?

  3. #3
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    im getting confused as to how i would point to the headItem using the currentItem?

  4. #4
    Run! Forrest Gump! TalosChen's Avatar
    Join Date
    May 2006
    Location
    Shanghai
    Posts
    27
    CategoryType is just NAME of a type, you should use:

    currentItem = currentCat->headItem;

    replace the currentCat with any pointer you want to really use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  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