error syntax error before {
Hey guys i have a project that im working on and i have an error everytime i compile.
It has several files this program so i have attatched the files onto this thread.
It says on line 222 in ts_utility.c syntax error before or at { error code 2
Could someone please help me solve it thanks..
Code:
/****************************************************************************
* COSC1098/1283 - Assignment #2 - Tennis Store
* Programming Principles 2A/Programming Techniques
* Author : <insert name here>
* Student Number : <insert student number here>
* Yallara Username : <insert username here>
* Start up code provided by Steven Burrows - [email protected]
****************************************************************************/
#include "ts.h"
#include "ts_utility.h"
#include "ts_options.h"
/****************************************************************************
* Function readRestOfLine() is used for buffer clearing. Source:
* https://inside.cs.rmit.edu.au/~pmcd/teaching/C-Prog/CourseDocuments/
* FrequentlyAskedQuestions/
****************************************************************************/
void readRestOfLine()
{
int c;
/* Read until the end of the line or end-of-file. */
while ((c = fgetc(stdin)) != '\n' && c != EOF)
;
/* Clear the error and end-of-file flags. */
clearerr(stdin);
}
/****************************************************************************
* Initialises the system to a safe empty state.
****************************************************************************/
void systemInit(TennisStoreType* ts)
{
}
/****************************************************************************
* Loads all data into the system.
****************************************************************************/
void loadData(TennisStoreType* ts, char* customerFile, char* stockFile)
{
/* declaration of variables*/
char* stockID;
char* description;
char* custID;
char* surname;
char* firstName;
char* address;
char* suburb;
char sTmp[100];
char cTmp[100];
char* unitpricePtr;
char* stocklevelPtr;
char* postCodePtr;
char* phoneNumPtr;
double unitprice;
int stocklevel;
int postCode;
int phoneNum;
/* pointing nodes to customer variables*/
CustomerNodeType* newCust;
CustomerNodeType* curCust;
CustomerNodeType* prevCust;
/* variables for files*/
FILE *cFile;
FILE *sFile;
if((cFile = fopen(customerFile, "r")) == NULL || (sFile = fopen(
stockFile,"r")) == NULL)
{
fprintf(stderr, "error opening file\n");
exit(EXIT_FAILURE);
}
else
{
printf("file was opened correctly");
}
while(fgets(cTmp, 100, cFile ) != NULL)
{
/* tokenizing variables*/
custID = strtok(cTmp, ",");
surname = strtok(NULL, ",");
firstName = strtok(NULL, ",");
suburb = strtok(NULL, ",");
postCodePtr = strtok(NULL, ",");
phoneNumPtr = strtok(NULL,"/0");
postCode = atoi(postCodePtr);
phoneNum = atoi(phoneNumPtr);
/* allocating memory using malloc for nodes*/
prevCust = malloc(sizeof(*prevCust));
curCust = malloc(sizeof(*curCust));
newCust = malloc(sizeof(*newCust));
/* start of linked list*/
curCust = ts -> headCust;
prevCust = NULL;
while(curCust !=NULL)
{
prevCust = curCust;
curCust = curCust -> nextCust;
}
/* copy the string variables into newCust node*/
strcpy(newCust->custID,custID);
strcpy(newCust->surname,surname);
strcpy(newCust->firstName,firstName);
strcpy(newCust->address,address);
strcpy(newCust->suburb,suburb);
/* newCust is postCode*/
newCust->postCode=postCode;
/* newCust is phoneNum*/
newCust->phoneNum=phoneNum;
/* printing the preloaded data*/
printf("\n\t%s",newCust -> custID);
printf("\t%s", newCust -> firstName);
printf("\t%s", newCust -> surname);
printf("\t%s", newCust -> address);
printf("\t%s", newCust -> suburb);
printf("\t%d", newCust -> postCode);
printf("\t%d", newCust -> phoneNum);
/* keep count of each customer in loop*/
ts -> customerCount++;
/* start of linked list*/
if(prevCust == NULL)
{
ts ->headCust = newCust;
}
else
{
prevCust -> nextCust = newCust;
}
/* if there is a previous node get the next node and make
it the new node*/
}
fclose(sFile);
while(fgets(sTmp, 100, sFile) != NULL)
{
/* tokenizing each field from comma*/
stockID = strtok(sTmp, ",");
description = strtok(NULL, ",");
unitpricePtr = strtok(NULL,",");
stocklevelPtr = strtok(NULL, "/0");
/* cast the Ptr character to an integers
unitprice = atoi(unitpricePtr);
stocklevel = atoi(stocklevelPtr);
prevStock = malloc(sizeof(*prevStock));
curStock = malloc(sizeof(*curStock));
newStock = malloc(sizeof(*newStock));
curStock = ts -> headStock;
prevStock = NULL;
while(curStock != NULL)
{
prevStock = curStock;
curStock = curStock -> nextStock;
}
ts -> stockCount++;
if(prevStock == NULL)
{
ts->headStock=newStock;
}
else
{
prevStock->nextStock=newStock;
}
}
fclose(sFile);
}
/****************************************************************************
* Deallocates memory used in the program.
****************************************************************************/
void systemFree(TennisStoreType* ts)
{
}
I couldnt submit the exstra file ts_utility.h
Code:
#ifndef TS_UTILITY_H
#define TS_UTILITY_H
/* Function prototypes. */
void readRestOfLine();
void systemInit(TennisStoreType* ts);
void loadData(TennisStoreType* ts, char* customerFile, char* stockFile);
void systemFree(TennisStoreType* ts);
#endif