I have 2 errors in this project thats due in 20 min and from what the books says the syntax is correct but in bloodshed I recive 2 compile time errors.... Does anyone know whats wrong... please help.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STRUCTOTAL 1000
#define CHARMAX 20
struct names{ /*begin structure*/
char name[CHARMAX]; /*char array for names*/
int attendance; /*0=absent 1=present*/
struct names *next;
}; /*end structure */
int mycomp(const void *p1,const void *p2);
int main(int argc, char *argv[])
{
struct names *head= NULL;
struct names *prev, *current;
char fname[CHARMAX];
char lname[CHARMAX];
char name[CHARMAX];
int total=0; /*total # of strings*/
int status=0; /*status of person-1=1st try,2=2nd try,3=admitted,4=denied*/
int choice=0; /*menu choice*/
int denied=0; /*counter for # of people denied access*/
int present=0; /*counter for # of people present*/
int n=0; /*counter for char*/
FILE *in; /*declare file pointer*/
/********************************FILE CHECK********************************/
if (argc<2) /*check for input file*/
{
printf("Usage %s filename\n",argv[0]);
exit(1);
}
if ((in=fopen(argv[1],"r"))==NULL)
{
printf("I couldn't open the file\"%s\"\n",argv[1]);
exit(2);
}
/***********************READ FILE AND SORT INTO 1ST AND LAST*********/
do
{
while((fname[n]=fgetc(in))!=' '&& fname[n]!= EOF)
n++; /*copy 1st name to structure*/
if (fname[n]!=EOF) /*add null to make a string*/
{
fname[n]='\0';
n=0; /*reset char counter*/
}
while((lname[n]=fgetc(in))!='\n'&& fname[n]!=EOF)
n++; /*copy last name to structure*/
if (lname[n]!=EOF)
{
lname[n++]=' '; /*add 1 space between last and first name*/
lname[n]='\0'; /*add null to make string*/
strcat(lname,fname); /*append to make 1 string*/
current=(struct names*)malloc(sizeof(struct names));
if (head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
strcpy(current->name,lname);
prev=current;
n=0;
total++;
}
}
while(fname[0]!=EOF&&lname[0]!=EOF);
qsort(head,total,sizeof(struct names),mycomp);
/*************************************DATA ENTRY******************************/
while(choice!=2)
{
printf("Choose an option\n1 Enter name\n2 Print reports and Quit\n");
scanf("%d",&choice);
getchar(); /*eat up <enter> from scanf*/
status=0;
while(status<3 && choice==1)
{
n=0;
status++;
printf("Enter name of shareholder in standard form (First name<space>Last name)\n");
/*******CONVERT NAME ENTERED INTO 1 STRING(LAST NAME FIRST)********/
while((fname[n]=getchar())!=' ')
n++;
fname[n]='\0';
n=0; /*reset char counter*/
while((name[n]=getchar())!='\n')
n++;
name[n]=' ';
n++; /*add 1 space at end of last name*/
name[n]='\0'; /*add null to last name to make string*/
strcat(name,fname); /*append to make 1 string*/
/*********************COMPARE STRINGS TO STRUCTURE ARRAY************/
current=head;
while(current!=NULL)
{
if(strcmp(current->name,name)==0) /*is name on list?*/
{
current->attendance=1; /*if admitted mark as present*/
status=3; /*loop status = present*/
printf("%s may enter\n",name);
present++; /*counter- # of people present*/
}
current=current->next;
}
if (status==1) /*if not on list first try*/
printf("%s is not on the list please re-enter\n",name);
if (status==2) /*if not on list second try*/
{
printf("%s is not authorized to enter\n",name);
status=4; /*denied admittence*/
denied++;
}
}
}
printf("The total number of shareholders is %d\n",total);
printf("The number of shareholders present is %d\n",present);
printf("%d people were denied acces to the meeting\n",denied);
current=head;
while(current!=NULL)
{
if(current->attendance==1)
printf("Present %s\n",current->name);
else
printf("Absent %s\n",current->name);
current=current->next;
}
}
int mycomp(const void *p1,const void *p2)
{
const struct names *ps1=p1;
const struct names *ps2=p2;
if (strcmp(ps1->name,ps2->name)>0)
return 1;
else if (strcmp(ps1->name,ps2->name)<0)
return -1;
}