T
toch3
im making a new ANSI-C program Address Book...by myself but cannot
run...i cant figure out why...im newbie in programming..could anyone
correct the coding for me...plz..
***************************************************************************************************
Write the program in
ANSI-C, using the libraries that you have learnt. Below is a list of
libraries
that you are allowed to use:
· stdio.h
· stdlib.h
· string.h
· math.h
· time.h
Simple Contact Book
Write a program that is capable of acting as a simple contact book. The
range of
functions that this simple contact book should have includes:
· Adding contacts
· Deleting contacts
· Searching contacts (based on name)
· Edit contacts
· Listing contacts (sorted in alphabetical order based on name)
All the contacts must be saved into a file, which can be retrieved and
update by the
program.
Below is the information is the contact book is required to store:
· Name
· Birthday
· Hand phone number
· Address
*********************************************************************************************************
#include<stdio.h>
#inlcude<stdlib.h>
static int cno
typedef char *string; //renaming type char as string
typedef struct //renaming sturcture as students
{
string first_name[50]:; //can also be string *first name
string last_name[50]:;
int age;
string ssn;
char gender;
string phone_number[20];
string address[100];
}contacts; //type students
contacts ininfo(void); //function in program
contacts modify(void);
contacts delete(void);
contacts search(void);
const int size=60; //in program student student_record
void main()
{
int choice;
contact c[100];
contact tmp;
puts("1) Enter new contact information and save to disk");
puts("2) Modify a record");
puts("3) delete information");
puts("4) Print list");
puts("5) Search");
puts("6) Exit");
puts("Please make a choice");
scanf("%i",&choice);
switch(choice)
{
case 1:
c[cno++]=tmp.ininfo();
break;
case 2:
c[cno++]=tmp.modify();
break;
case 3:
contacts tp;
int cono;
puts("contact number:\n");
scanf("%d",&cono);
c[cono]=tmp.delete();
break;
case 4:
for(i=0;i<cno;i++)
{
printf("%s /n %s /n %d /n %s /n %s /n
%s",c.first_name,c.last_name,c.age,c.gender,c.phone_number,c.address;
}
break;
}
}
contacts ininfo(void)
{
contacts temp;
puts("first name:\n");
scanf("%s",temp.first_name);
puts("last name:\n");
scanf("%s",temp.last_name);
puts("age:\n");
scanf("%i",&temp.age);
puts("gender: (M or F)");
scanf("%s", temp.gender);
puts("SSN:\n");
scanf("%s", temp.ssn);
puts("Phone number:\n");
scanf("%s",temp.phone_number);
puts("Address:\n");
scanf("%s", temp.address);
return temp;
}
contacts modify(void)
{
contacts temp;
int conno;
puts("contact number:\n");
scanf("%d",&conno);
for(i=0;i<cno;i++)
{
if(conno==i)
{
scanf("%s",temp.first_name);
puts("last name:\n");
scanf("%s"temp.last_name);
puts("age:\n");
scanf("%i",&temp.age);
puts("gender: (M or F)");
scanf("%s", temp.gender);
puts("SSN:\n");
scanf("%s", temp.ssn);
puts("Phone number:\n");
scanf("%s",temp.phone number);
puts("Address:\n");
scanf("%s", temp.address);
return temp;
}
}
}
contacts delete(void)
{
contacts temp;
int conno;
puts("contact number:\n");
scanf("%d",&conno);
for(i=0;i<cno;i++)
{
if(conno==i)
{
temp.first_name="";
temp.last_name="";
temp.gender="";
temp.phone number="";
temp.address="";
}
}
}
contacts search();
{
contacts temp;
string fn;
puts("first name:\n");
scanf("%s",fn);
for(i=0;i<cno;i++)
{
if(fn=temp.first_name)
{
printf("%s /n %s /n %d /n %s /n %s /n
%s",c.first_name,c.last_name,c.age,c.gender,c.phone_number,c.address;
}
}
}
*******************************************************************************************************
plz help tq
run...i cant figure out why...im newbie in programming..could anyone
correct the coding for me...plz..
***************************************************************************************************
Write the program in
ANSI-C, using the libraries that you have learnt. Below is a list of
libraries
that you are allowed to use:
· stdio.h
· stdlib.h
· string.h
· math.h
· time.h
Simple Contact Book
Write a program that is capable of acting as a simple contact book. The
range of
functions that this simple contact book should have includes:
· Adding contacts
· Deleting contacts
· Searching contacts (based on name)
· Edit contacts
· Listing contacts (sorted in alphabetical order based on name)
All the contacts must be saved into a file, which can be retrieved and
update by the
program.
Below is the information is the contact book is required to store:
· Name
· Birthday
· Hand phone number
· Address
*********************************************************************************************************
#include<stdio.h>
#inlcude<stdlib.h>
static int cno
typedef char *string; //renaming type char as string
typedef struct //renaming sturcture as students
{
string first_name[50]:; //can also be string *first name
string last_name[50]:;
int age;
string ssn;
char gender;
string phone_number[20];
string address[100];
}contacts; //type students
contacts ininfo(void); //function in program
contacts modify(void);
contacts delete(void);
contacts search(void);
const int size=60; //in program student student_record
void main()
{
int choice;
contact c[100];
contact tmp;
puts("1) Enter new contact information and save to disk");
puts("2) Modify a record");
puts("3) delete information");
puts("4) Print list");
puts("5) Search");
puts("6) Exit");
puts("Please make a choice");
scanf("%i",&choice);
switch(choice)
{
case 1:
c[cno++]=tmp.ininfo();
break;
case 2:
c[cno++]=tmp.modify();
break;
case 3:
contacts tp;
int cono;
puts("contact number:\n");
scanf("%d",&cono);
c[cono]=tmp.delete();
break;
case 4:
for(i=0;i<cno;i++)
{
printf("%s /n %s /n %d /n %s /n %s /n
%s",c.first_name,c.last_name,c.age,c.gender,c.phone_number,c.address;
}
break;
}
}
contacts ininfo(void)
{
contacts temp;
puts("first name:\n");
scanf("%s",temp.first_name);
puts("last name:\n");
scanf("%s",temp.last_name);
puts("age:\n");
scanf("%i",&temp.age);
puts("gender: (M or F)");
scanf("%s", temp.gender);
puts("SSN:\n");
scanf("%s", temp.ssn);
puts("Phone number:\n");
scanf("%s",temp.phone_number);
puts("Address:\n");
scanf("%s", temp.address);
return temp;
}
contacts modify(void)
{
contacts temp;
int conno;
puts("contact number:\n");
scanf("%d",&conno);
for(i=0;i<cno;i++)
{
if(conno==i)
{
scanf("%s",temp.first_name);
puts("last name:\n");
scanf("%s"temp.last_name);
puts("age:\n");
scanf("%i",&temp.age);
puts("gender: (M or F)");
scanf("%s", temp.gender);
puts("SSN:\n");
scanf("%s", temp.ssn);
puts("Phone number:\n");
scanf("%s",temp.phone number);
puts("Address:\n");
scanf("%s", temp.address);
return temp;
}
}
}
contacts delete(void)
{
contacts temp;
int conno;
puts("contact number:\n");
scanf("%d",&conno);
for(i=0;i<cno;i++)
{
if(conno==i)
{
temp.first_name="";
temp.last_name="";
temp.gender="";
temp.phone number="";
temp.address="";
}
}
}
contacts search();
{
contacts temp;
string fn;
puts("first name:\n");
scanf("%s",fn);
for(i=0;i<cno;i++)
{
if(fn=temp.first_name)
{
printf("%s /n %s /n %d /n %s /n %s /n
%s",c.first_name,c.last_name,c.age,c.gender,c.phone_number,c.address;
}
}
}
*******************************************************************************************************
plz help tq