Hello, I am new to this forum and I don't really know exactly how this works. I am wondering if anyone who is good with C Programming could help me, I am very basic at this and I am taking a class in college and totally lost :P. But here we go, and Thanks ahead for any type of help, I thoroughly appreciate it.
The Program: A basic phonebook written in C. The use has to add contact, delete, and show the contacts utilizing: structs and dynamic memory allocation.
I have written this code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Defining my variables
int entry;
int contactsnum=0;
int i=0;
//Defining my struct
typedef struct phonebook
{
char firstName[20];
char lastName[20];
char number[20];
}con;
//Attempting to create a code for adding and removing items in con struct
con * AddItem (con * conlist);
con * RemoveItem (con * conlist);
//main function
main(){
phonebook entry[100];
phonebook* contacts;
con=(phonebook*)malloc(sizeof(con)*sizeof(con));
//problem with this line compiler won't compile
con p;
int choice=0;
//A do while loop allows for constent adding and remove
do{
con listmember, *conlist;
char firstName[20];
char lastName[20];
char number[11];
printf("Hello, Welcome to Command Prompt Phonebook.\n");
printf("Please Select an option:\n");
printf("(1) Add Contact\n");
printf("(2) Delete Contact\n");
printf("(3) Search Phonebook\n");
printf("(4) Exit Program\n");
printf("Enter Selection:");
scanf("%d",&choice);
//switch for choices
switch(choice){
case 1:
printf("\nYou chose Add Contact:\n");
printf("\nPlease Enter First Name:");
scanf("%s",&p.firstName);
conlist=AddItem (contact,p.firstName);
printf("\nPlease Enter Last Name:");
scanf("%s",&p.lastName);
conlist=AddItem (con,p.lastName);
printf("\nPlease Enter Phone Number:");
scanf("%s",&p.number);
conlist=AddItem (con, number);
printf("\nNumber Added to Phonebook");
break;
/* The code I wrote here doesn't work. I get "expected
primary-expresion before '=' token" I don't really understand
whats wrong with it */
case 2:
printf("You chose Delete Contact:");
printf("Please Enter First Name:");
scanf("%d",&p.firstName);
conlist=RemoveItem (con,p.firstName);
printf("Please Enter Second Name:");
scanf("%d",&p.lastName);
conlist=RemoveItem (con,p.lastName);
printf("Please Enter Number:");
scanf("%f",&p.number);
conlist=RemoveItem (con,p.number);
printf("Number has been deleted");
break;
// Same problem
case 3:
printf("\nCommand Prompt Phonebook Contents:");
printf("\nFirst Name:%d",&p.firstName);
printf("\nLast Name:%d",&p.lastName);
printf("\nPhone Number:%f",&p.number);
break;
// Haven't really worked at this yet
default:
printf("Please Enter Valid Number");
case 4:
break;
}
}while(choice!=4);
printf("\nThanks for using! Goodbye!\n");
system("pause");
}
I have many problems in my syntax I assume, but being very basic I have no idea what to do. I would really apprecaite help; but, I'm sure this board gets many questions like this so I don't expect alot of help. I do thoroughly apprecaite even slight help. I'm not asking for you to write it how it SHOULD be but point me in the direct I need to look.
Thanks Again,
Ryan



LinkBack URL
About LinkBacks


