Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,600 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 964 people online right now. Registration is fast and FREE... Join Now!




one error in my address book function file!

 
Reply to this topicStart new topic

one error in my address book function file!, parse error... I don't see it!

acsusf12
post 15 Jul, 2008 - 03:35 PM
Post #1


New D.I.C Head

*
Joined: 22 Jun, 2008
Posts: 7

ok sooooo.. when I compile this with my main file I get one parse error. The compiler says that it is before void in the first function, but I have no idea where it is because it looks fine to me! Any help would be awesome, and thanks in advance!

CODE

void bye(void)/*Bye to user*/
{
  printf("Thank you for using your addressbook.  Bye!");
}

void welcome(void)/*welcome message to user*/
{
   printf("Welcome to your address book!\n");
}

    void menu(void)/*prints menu to the screen*/
   {
      printf(" Please choose an option from the menu below:\n");
      printf("1. Add a new contact\n");
      printf("2. Delete an old contact\n");
      printf("3. Edit an existing contact\n");
      printf("4. Search for an existing contact\n");
   }

    void displayBook(book book1[], int conts)/*displays current address book to screen*/
   {
      stream file1 = fopen( "People.txt", "r");
      printf("\tAddress Book\n");
      printf("First name\tLast name\tAddress\tCity\tState\tPhone number\n");
      printf("-------------------------------------------------------------------\n");
      int x;
      for(x = 0; x<conts; x++)/*loops to display all contacts*/
      {
         printf("%s\t", book1[x].first);
         printf("%s\t", book1[x].last);
         printf("%80c\t", book1[x].address);
         printf("%s\t", book1[x].city);
         printf("%s\t", book1[x].state);
         printf("%s\n", book1[x].phone);
      }
      fclose(file1);
   }

    void addContact(book book1[], int *conts)
   {
      stream file1 = fopen( "People.txt", "a");
      int counter = *conts;
      char ans = 'y';
  
      while(ans == 'y')/*loops while user wants to add contacts to address book*/
      {
         printf("Enter the first name of the new contact:\n");
         scanf("%s", &book1[counter].first);
         printf("Enter the last name of the new contact:\n");
         scanf("%s", &book1[counter].last);
         printf("Enter the address of the new contact:\n");
         scanf("%80c", &book1[counter].address);
         printf("Enter the city of the new contact:\n");
         scanf("%s", &book1[counter].city);
         printf("Enter the state of the new contact(2 letter abbreviation):\n");
         scanf("%s", &book1[counter].state);
         printf("Enter the new contact phone number:\n");
         scanf("%s", &book1[counter].phone);
      
         counter++;
      
         fprintf(file1, "%s,", &book1[counter].first);/*prints new input to file*/
         fprintf(file1, "%s,", &book1[counter].last);
         fprintf(file1, "%80c,", &book1[counter].address);
         fprintf(file1, "%s,", &book1[counter].city);
         fprintf(file1, "%s,", &book1[counter].state);
         fprintf(file1, "%s\n", &book1[counter].phone);
      
         puts(" ");
         printf("Add another contact?\n");
         scanf("%c", ans);/*loop answer*/
         ans = tolower(ans);
      }
      *conts = counter;
      fclose(file1);
   }

    void deleteContact(book book1[], int conts)/*function to delete a contact*/
   {
      stream file1 = fopen( "People.txt", "a");
      int x;
      char ln[50];
      printf("Enter the last name of the contact you would like to delete:\n");
      scanf("%s", &ln);
      for(x = 0; x<conts; x++)/*loops to replace "deleted" content with following contact*/
      {
         if(strcmp(book1[x].last, ln) == 0)
         {    
            while(x<conts)
            {
               book1[x] = book1[x+1];
               x++;
            }
        
            conts--;
            break;
         }
      }
      for(x = 0; x<conts; x++)/*prints new output to file*/
      {
         fprintf(file1, "%s, ", &book1[x].first);
         fprintf(file1, "%s, ", &book1[x].last);
         fprintf(file1, "%80c, ", &book1[x].address);
         fprintf(file1, "%s, ", &book1[x].city);
         fprintf(file1, "%s, ", &book1[x].state);
         fprintf(file1, "%s, ", &book1[x].phone);
      }
      fclose(file1);
   }

    void editContact(book book1[], int conts)/*function to edit one contact out of the file*/
   {
      stream file1 = fopen( "People.txt", "a");
      int x, an;
      char ln[50];
      printf("Enter the last name of the contact you would like to edit:\n");
      scanf("%s", &ln);
      for(x = 0; x<conts; x++)/*loops through entire address book*/
      {
         if(strcmp(book1[x].last, ln) == 0)/*compares last name entered to contacts to find one to edit*/
         {
            printf("%s\t%s\t%80c\t%s\t%s\t%s\n", book1[x].first, book1[x].last, book1[x].address, book1[x].city, book1[x].state, book1[x].phone);
            printf("What would you like to edit?\n1. First name\n2. Last name\n3. Address\n4. City\n5. State\n6. Phone Number\n");
            printf("Enter the number of the option you choose:\n");
            scanf("%i", &an);
            switch(an)/*user enters choice of what they want to edit in the contact*/
            {
               case 1:
                  printf("Enter the new first name:\n");
                  scanf("%s", book1[x].first);
                  break;
               case 2:
                  printf("Enter the new last name:\n");
                  scanf("%s", book1[x].last);
                  break;
               case 3:
                  printf("Enter the new address:\n");
                  scanf("%80c", book1[x].address);
                  break;
               case 4:
                  printf("Enter the new city:\n");
                  scanf("%s", book1[x].city);
                  break;
               case 5:
                  printf("Enter the new state (two letter abbreviation):\n");
                  scanf("%s", book1[x].state);
                  break;
               case 6:
                  printf("Enter the new phone number (area code first):\n");
                  scanf("%s", book1[x].phone);
                  break;
               default:
                  printf("Error: not a valid option\n");
                  break;
            }
            for(x = 0; x < conts; x ++)
            {
               fprintf(file1, "%s,", book1[x].first);
               fprintf(file1, "%s,", book1[x].last);
               fprintf(file1, "%80c,", book1[x].address);
               fprintf(file1, "%s,", book1[x].city);
               fprintf(file1, "%s,", book1[x].state);
               fprintf(file1, "%s\n", book1[x].phone);
            }
         }
      }
      fclose(file1);
   }

    void search(book book1[], int conts)/*function to search and display one contact in address book*/
   {
      stream file1 = fopen( "People.txt", "r");
      int x;
      char ln[50];
      printf("Enter the last name of the contact you are searching for\n");
      scanf("%s", &ln);
      for(x = 0; x<conts; x++)/*searches through entire contact list by last name*/
      {
         if(strcmp(book1[x].last, ln) == 0)/*compares every name to find the right one to display*/
         {
            printf("First name\tLast name\tAddress\tCity\tState\tPhone number\n");
            printf("--------------------------------------------\n");
            printf("%s\t%s\t%80c\t%s\t%s\t%s\n", book1[x].first, book1[x].last, book1[x].address, book1[x].city, book1[x].state, book1[x].phone);
            break;
         }
      }
      fclose(file1);
   }


User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month