For some reason I keep on getting a segmentation error when trying to run the code.
Does anyone know how I can fix it?:
Code:
#include <stdio.h>
#include <string.h>
#define MAXLEN 120
void checkin()
{
typedef struct {
char reservationId[7];
char customerId[7];
char roomId[5];
int numGuests;
char startDate[10];
char endDate[10];
char status[10];
}bookingdata;
bookingdata record[100];
FILE * filehandle;
char line[MAXLEN];
char *item = NULL;
int reccount = 0;
int k;
/* Here comes the actions! */
/* open file */
filehandle = fopen("booking.txt","r");
/* Read file line by line */
while (fgets(line,MAXLEN,filehandle))
{
printf("%s",line);
item = strtok(line," ");
strcpy(record[reccount].reservationId,item);
item = strtok(NULL," ");
strcpy(record[reccount].customerId, item);
item = strtok(NULL," ");
strcpy(record[reccount].roomId, item);
item = strtok(line," ");
record[reccount].numGuests = atoi(item);
item = strtok(NULL," ");
strcpy(record[reccount].startDate, item);
item = strtok(NULL,"\n");
strcpy(record[reccount].endDate, item);
//printf("%s\n",record[reccount].day);
reccount++;
}
/* Close file */
fclose(filehandle);
/* Loop through and report on data */
printf("Weather Record\n");
for (k=0; k<reccount; k++) {
printf("It is %s\n",record[k].reservationId);
}
}
main()
{
checkin();
}