Thread: Last 2 errors in project

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    46

    Angry Last 2 errors in project

    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;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > but in bloodshed I recive 2 compile time errors.... Does anyone
    > know whats wrong... please help.

    Well, we might know what was wrong if you told us what the errors were!

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Project Help please!
    By black_hole??? in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2009, 12:55 AM
  2. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  3. Project details: Dedicated
    By Stack Overflow in forum Projects and Job Recruitment
    Replies: 9
    Last Post: 02-22-2005, 03:10 PM
  4. DJGPP project problems
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-08-2002, 07:16 PM