C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-08-2009, 11:28 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 3
Help on Program

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
sharpshot67 is offline   Reply With Quote
Old 10-08-2009, 11:51 PM   #2
Registered User
 
Join Date: Sep 2006
Posts: 2,506
Welcome to the forum, Ryan!

Whenever you post code, highlight it the code, and then click on the # icon of the window where you enter text.

That makes your code *MUCH* easier to read.

Please edit your last post, and add the code tags (as they're called), around your program.

I'll look at it in a bit.
Adak is online now   Reply With Quote
Old 10-09-2009, 09:09 PM   #3
Registered User
 
Join Date: Oct 2009
Posts: 3
My apologies

Thanks for the welcome, I assume I will be using this resource alot during my time at CECS school haha.Thanks for the responce and I apologize for not knowing but here is the code again:

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");
}
Thanks again for all the help!
sharpshot67 is offline   Reply With Quote
Old 10-10-2009, 01:32 AM   #4
Registered User
 
Join Date: Oct 2009
Location: While(1)
Posts: 316
There are so many problems dude in the code rectify one by one i can pinpoint one or two here by just one go through here

if u r compiling your code with gcc the put in the following lines struct like
Code:
struct phonebook entry[100];
struct phonebook* contacts;
Code:
con=(phonebook*)malloc(sizeof(con)*sizeof(con));
Don't know what you want to do with above piece of code. as you already said con is global structure object that will be available through the file why u wanna allocate some ........ peice of memory to don't understand that

here Additem
Code:
conlist=AddItem (con,p.lastName);
is taking two parameters while the signature obove is taking one parameter how the compiler can compile this god knows
[code]
//Attempting to create a code for adding and removing items in con struct
con * AddItem (con * conlist);
con * RemoveItem (con * conlist);

[/code


try to solve these kind of bugs if the problem will not solve please post again the code with modifications

c y
RockyMarrone is offline   Reply With Quote
Old 10-10-2009, 03:51 PM   #5
Registered User
 
Join Date: Oct 2009
Posts: 3
Haha! I know its completely filed with problems. This is my first time learning C Programing and I have absolutely no idea what I'm doing. I really appreciate the help, I will go back and try to get it working, or at least half way because todays the day to send her in.

Thanks again for all the help!

Ryan

P.S. I will be back numerous times I can already tell. I love this place
sharpshot67 is offline   Reply With Quote
Reply

Tags
basic, chelp, helpme, noob, phonebook

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with program that's calling a function and has a loop tigerfansince84 C++ Programming 9 11-12-2008 01:38 PM
Need help with a program, theres something in it for you engstudent363 C Programming 1 02-29-2008 01:41 PM
This is a simple program.. Help me please I think it has an error.. lesrhac03 C Programming 4 02-21-2008 10:39 AM
My program, anyhelp @licomb C Programming 14 08-14-2001 10:04 PM


All times are GMT -6. The time now is 11:36 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22