CANNOT RUN!!!!! any idea why?

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];
}contact; //type students
students ininfo(void); //function in program


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) Search student information");
puts("4) Print a students information");
puts("5) 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;
}


}
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="";

}
}

}
 
G

Gordon Burditt

im making a new ANSI-C program Address Book...by myself but cannot

How do you *KNOW* it won't run? If it doesn't compile (and if this
is what you tried to compile, it shouldn't), give the error messages.
i cant figure out why...im newbie in programming..could anyone
correct the coding for me...plz..

Please provide the email address of your instructor so we
can turn in the assignment directly.
***************************************************************************************************
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

Header files are not libraries. Standard C says you are allowed to
use more header files than this, and Standard C overrides homework
assignments.
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

The code below also refers to the SSN. The name, birth date, and
SSN of a person other than yourself should never be stored on the
same computer together. The US Veterans Administration is learning
this the hard way. Ideally the only copies of SSNs are stored in
the sun.
*********************************************************************************************************
#include<stdio.h>
#inlcude<stdlib.h>
static int cno

missing semicolon above.
typedef char *string; //renaming type char as string

No, this does *NOT* rename type char as string.
And why bother? It just confuses you.
typedef struct //renaming sturcture as students
{

string first_name[50]:; //can also be string *first name

string first_name[50] and string *first_name *DO NOT* do the same thing.
string last_name[50]:;
int age;
string ssn;
char gender;
string phone_number[20];
string address[100];
}contact; //type students
students ininfo(void); //function in program


const int size=60; //in program student student_record
void main()

main() returns int, not void.
{
int choice;
contact c[100];
contact tmp;

Indentation is your friend. Use it.
puts("1) Enter new contact information and save to disk");
puts("2) Modify a record");
puts("3) Search student information");
puts("4) Print a students information");
puts("5) Exit");
puts("Please make a choice");
scanf("%i",&choice);
switch(choice)
{
case 1:
c[cno++]=tmp.ininfo();
tmp does not have a member function named ininfo. This is not C++.
And even if it was, you'd have to write code for such a member function.
break;
case 2:
c[cno++]=tmp.modify();
tmp does not have a member function named modify. This is not C++.
break;
case 3:
contacts tp;
int cono;
puts("contact number:\n");
scanf("%d",&cono);

c[cono]=tmp.delete();
tmp does not have a member function named delete. This is not C++.
break;
}


}
contacts ininfo(void)
{
contacts temp;

What prevents the user from inputting (inadvertently or maliciously)
a string that is too long and overflowing the buffer? If Microsoft
wrote this code they'd probably have to issue a critical update
patch for it.

I'd also like to point out that %s does not allow a space inside a
first or last name or phone number, and that real-life names don't
obey these restrictions. Also, your length restriction of 20 for
a phone number is unlikely to work for a phone number stated
as "1-800-555-1212 extension 5383".
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)
{

This function looks for a contact entry, and then conditionally
clears a temporary variable, which it then throws away. In
what way does this delete anything?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top