hi all, ive moved on to the next thing and its killing me, i dont even know really how to begin. the section is all about making a main function and writing other .h files and using them in the main function. basically its a phone book using structures and pointer arrays. the ability to add more information and allocate the necessary memory. also to later be able to edit the information stored and write it to a file. this is the little that im pretty sure is not right at all. thanks for the help ahead of time, im gonna need it with this one.

Program Info:


1. Create a phone book program that allows users to enter names and phone numbers of friends and acquaintances. Create a structure to hold contact information and use calloc to reserve the first memory segment. The user should be able to add phone book entries through a menu in a loop. Use the realloc function to add contiguous memory segments to the original memory block when a user adds a new phone book entry.
Your structure should hold first name, last name, email address, and phone number.

Hint: Your main program should create the structure in a header file called “main.h”.

main.h should look like the following:

typedef struct contact {
char first[20];
char last[20];
char email[20];
char phone[10];
} c;


Your main.c program should create a dynamic array of these structures and then dynamically allocate memory as necessary. The main.c program will contain the menu. Your individual functions will ask the users for the appropriate values.

You will need to create an external function called add with the following signature. Create this in the header file process.h

void add( c*, int ); where c* is the array of structures, and int is the number of the current address to be added to the book.

2. Create the ability to edit contact information for a person (Add it to your menu). Ask the user for the first name, last name of the contact to edit. Search through your array and find the item. If the person is not in the list, then print a message to the user saying that. If the person is in the list, ask them for the new email address and phonenumber and update the structure accordingly.

Add the following prototype to the file process.h

Void edit( c*, int );
Where c* is the array of structures, and int is the current index to be edited.
Edit will modify the user information in the array of structures.


3. Add the ability (another menu option) to save your contact information to a file. The data should be stored as name emailaddress phonenumber






My Code So Far
the main.c program
Code:
#include <stdio.h>
#include <stdlib.h>

#include "main.h"
#include "process.h"

int main() {
    int entries, i;
    c *entry;
    *ptrC = c;
    c *newc;
    int choice;
    
    c = (int *) calloc (1, sizeof(int));
    
        if (c == (int *) NULL)
    {
          printf("\n Failed to allocate grades in array\n");
          exit(1);
    }
    
    while (choice != 5); {
    printf("Welcome to the Phonebook\n\n");      
    printf("1)Add entries to phone book.\n");
    printf("2)To edit entries.\n");
    printf("3)Print Phonebook.\n");
    scanf("%d", &choice);
    

                 if (choice = 1){
                            printf("Enter the number of phone book entries:");
                            scanf("%d", &entries); 
                            add (c*, entries);
                            }
                 if (choice = 2) {
                            edit(c*, i);
                            }
                 if (choice = 3)
                            {
                                //havent gotten to yet
                                }
                                }
                 system("PAUSE");
                 
                 return 0;



the main.h
Code:
typedef struct contact {
    char first[20];
     char last[20];
    char email[20];
   char phone[10];
                        } c;
 
 
 void add(c*, int entries){

                                   
               
                  newc = realloc (c, entries * sizeof(int));
                  
                  if (newc == NULL) {
                           printf("out of memory.");
                                     }
                  else 
                         c = newc;

    
                             for( i = 0; i < entries; i++ ) {  
                               printf("Enter first name:\n");
                                 scanf("%s", &c[i].first);

                                 printf("Enter last name:\n");
                                 scanf("%s", &c[i].last);

                                 printf("Enter email:\n");
                                 scanf("%s", &c[i].email);
      
                                 printf("Enter phone:\n");
                                 scanf("%s", &c[i].phone);
                                                           }
                             }
                 
                 free(c);
                 free(newc);


the process.h

Code:
void add(c*, int);
void edit(c*, int);