Help me/....

T

toch3

i am writing a c program that is basically an address book. the only
header we are using is #include<stdio.h> we are to use a global array,
loops, and pointers. we are to have a menu at the beginning. 1. add new
record 2. search for a record 3 modify a record 4. delete a record 5.
view all records 6.exit in each of these menu's we are to be able to
print the record to an exterior printer.
: i have started my global array, and program, but for some reason i am
not getting it to run, and i am lost on how to actually set this
program up.
:
: if somebody has a simple addressbook program using #include<stdio.h>
as the only header i can look at for guidance this would be great.Any
header also can.


here's my code..

**********************************************************************************************************
#include<stdio.h>
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];
}students; //type students
students getinfo(void); //function in program
//void display (students student_records[]);
//will display user selected student record
const int size=60; //in program student student_record
void main()
{
int choice; //decloration of int
puts("1) Enter student 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: printf("Please follow the prompts to enter the student
information");
{
students;
break;
}
case 2: printf("What record would you like to modify?");
{
break;
}
case 3: printf("Please follow prompts to search records");
{
break;
}
case 4: printf("This will print a students record");
{
break;
}
case 5: printf("Thank you for using my program");
{
break;
}
}
}
{
students student_record;
student_record=getinfo();
//display(student1);
}
students getinfo(void)
{
students 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;
}
***********************************************************************************************************

anyone could give me any full example code for address book in
acsi-c..for guidance
 
B

Bill Pursell

toch3 said:
here's my code..
#include<stdio.h>
typedef char *string; //renaming type char as string

This is an unnecessary comment. In particular, a good
rule of thumb is "when the comments don't match the code,
both are wrong." In this case, the comment doesn't
match the code, since you've defined string as a
char pointer, not a char.
typedef struct //renaming sturcture as students

This comment is bogus as well, since you aren't
renaming anything. You are defining the
structure.
{
string first_name[50]:; //can also be string *first name

And here are a few problems. One, the ':' is a syntax
error. Two, you've just declared first_name as being
an array of 50 char pointers. In other words, you
seem to expect each student to have a maximum
of 50 first names.
string last_name[50]:;
int age;
string ssn;
char gender;
string phone_number[20];
string address[100];
}students; //type students
students getinfo(void); //function in program

This comment is just annoying. When you declare
a function, it is obviously a function. Being redundant
is not helpful, and just clutters the code.
//void display (students student_records[]);
//will display user selected student record
const int size=60; //in program student student_record
void main()
{
int choice; //decloration of int

I will stop commenting on the irritation that this type of
comment creates, but I'll add that at the very least you
should attempt to use correct spelling.

scanf("%s"temp.first name);

The syntax error here is a missing ',' between
the format string and the argument. The
semantic error is that temp.firstname is
an array of char pointers, but you seem
to be attempting to treat it like an array of char.
 
O

osmium

toch3 said:
i am writing a c program that is basically an address book. the only
header we are using is #include<stdio.h> we are to use a global array,
loops, and pointers. we are to have a menu at the beginning. 1. add new
record 2. search for a record 3 modify a record 4. delete a record 5.
view all records 6.exit in each of these menu's we are to be able to
print the record to an exterior printer.
: i have started my global array, and program, but for some reason i am
not getting it to run, and i am lost on how to actually set this
program up.
:
: if somebody has a simple addressbook program using #include<stdio.h>
as the only header i can look at for guidance this would be great.Any
header also can.


here's my code..

**********************************************************************************************************
#include<stdio.h>
typedef char *string; //renaming type char as string

But it's *not* a char. It is a pointer *to* a char. Your comment is wrong.
typedef struct //renaming sturcture as students
{
string first_name[50]:; //can also be string *first name
string last_name[50]:;
int age;
string ssn;

Do you see the inconsistency here? You treat ssn differently than you do a
first_name. But they are very similar things. A name is a collection of
letters and an ssn is a collection of digits. Same deal. I suggest you get
rid of your notion of a string, I think it is confusing you. When you want
to use a string, do it like this:

char name[50].

Then you get a place to put the data automatically. You ssn is an accident
waiting to happen. What you have right now is a pointer that is pointing
God knows where. This may/will come back to bite you later.

I think you will want:

struct Student // capitalize types. good practice.
{
char name[30];
char gender;
... etc ;
};

struct Student book[50];
/*book is a variable. struct Student is a type. */

An address book can hold as many as 50 Students. Each student can have a
name of up to 29 characters.

<snip>
 
T

toch3

Reposting my Question with updated code I change with forumer
guidance..with syntax error i got while run it...really appreciate for
those who willing to help me..


****************************************************************************************************
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>
#include<stdlib.h>
static int cno;


struct student //renaming sturcture as students
{

char first_name[10]: //can also be string *first name
int age;
char ssn;
char gender;
char phone_number[10];
char address[10];
}
struct student book[60]; //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
int main()
{
int choice;
contact c[100]; //#define number_of_contacts 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;
}
}
}
******************************************************************************************************


((((SYNTAX error that i cant manage to figure out)))))

--------------------Configuration: AdressBook - Win32
Debug--------------------
Compiling...
AdressBook.c
(10) : error C2059: syntax error : 'type'
(15) : error C2059: syntax error : '}'
(18) : error C2061: syntax error : identifier 'ininfo'
(18) : error C2059: syntax error : ';'
(18) : error C2059: syntax error : 'type'
(27) : error C2065: 'contact' : undeclared identifier
(27) : error C2146: syntax error : missing ';' before identifier 'c'
(27) : error C2065: 'c' : undeclared identifier
(27) : error C2109: subscript requires array or pointer type
(28) : error C2146: syntax error : missing ';' before identifier 'tmp'
(28) : error C2065: 'tmp' : undeclared identifier
(40) : error C2109: subscript requires array or pointer type
(40) : error C2224: left of '.ininfo' must have struct/union type
(43) : error C2109: subscript requires array or pointer type
(43) : error C2224: left of '.modify' must have struct/union type
(46) : error C2065: 'contacts' : undeclared identifier
(46) : error C2146: syntax error : missing ';' before identifier 'tp'
(46) : error C2065: 'tp' : undeclared identifier
(47) : error C2143: syntax error : missing ';' before 'type'
(49) : error C2065: 'cono' : undeclared identifier
(51) : error C2109: subscript requires array or pointer type
(51) : error C2224: left of '.delete' must have struct/union type
(54) : error C2065: 'i' : undeclared identifier
(56) : error C2001: newline in constant
(57) : error C2001: newline in constant
(57) : error C2065: 's' : undeclared identifier
(57) : error C2296: '%' : illegal, left operand has type 'char [32]'
(57) : error C2143: syntax error : missing ')' before 'string'
(57) : error C2198: 'printf' : too few actual parameters
(64) : error C2146: syntax error : missing ';' before identifier
'ininfo'
(64) : warning C4013: 'ininfo' undefined; assuming extern returning int
(64) : error C2143: syntax error : missing ')' before 'type'
(64) : error C2059: syntax error : ')'
(68) : error C2065: 'temp' : undeclared identifier
(68) : error C2224: left of '.first_name' must have struct/union type
(70) : error C2224: left of '.last_name' must have struct/union type
(72) : error C2224: left of '.age' must have struct/union type
(74) : error C2224: left of '.gender' must have struct/union type
(76) : error C2224: left of '.ssn' must have struct/union type
(78) : error C2224: left of '.phone_number' must have struct/union type
(80) : error C2224: left of '.address' must have struct/union type
(85) : error C2061: syntax error : identifier 'modify'
(85) : error C2059: syntax error : ';'
(85) : error C2059: syntax error : 'type'
(115) : error C2061: syntax error : identifier 'delete'
(115) : error C2059: syntax error : ';'
(115) : error C2059: syntax error : 'type'
(137) : error C2061: syntax error : identifier 'search'
(137) : error C2059: syntax error : ';'
(137) : error C2059: syntax error : ')'
(138) : error C2449: found '{' at file scope (missing function header?)
(149) : error C2001: newline in constan
(150) : error C2001: newline in constant
(153) : error C2059: syntax error : '}'
Error executing cl.exe.

AdressBook.exe - 53 error(s), 1 warning(s)
******************************************************************************************************
 
B

Bill Pursell

toch3 said:
Reposting my Question with updated code I change with forumer
guidance..with syntax error i got while run it...really appreciate for
those who willing to help me..

#include<stdio.h>
#include<stdlib.h>

One comment: these are headers. Calling them libraries
is not correct. Your instructor should know better.
static int cno;
struct student //renaming sturcture as students
{
char first_name[10]: //can also be string *first name

((((SYNTAX error that i cant manage to figure out)))))
(10) : error C2059: syntax error : 'type'

A good rule of thumb: when you get a syntax
error on line 10, look at the end of line 9 for
a semi-colon. Leaving out the semi-colon
is a common error, and you've made it here.
 
O

osmium

:

Reposting my Question with updated code I change with forumer
guidance..with syntax error i got while run it...really appreciate for
those who willing to help me..


****************************************************************************************************
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>
#include<stdlib.h>
static int cno;


struct student //renaming sturcture as students

You can only rename things that already have a name. Did you get some advice
regarding capitalizing to distinguish type names?

{

char first_name[10]: //can also be string *first name

The comment not true. string is an unknown identifier in this program.

int age;
char ssn;
char gender;
char phone_number[10];
char address[10];
}
struct student book[60]; //type students

contacts ininfo(void) //function in program

How is the compiler supposed to know what "contacts" means? It appears to
be a user defined type (in this context, *you* are the user). Where do you
define it? Do you by chance mean stuct student?

contacts modify(void)
contacts delete(void)
contacts search(void)

const int size=60; //in program student student_record
int main()
{
int choice;
contact c[100]; //#define number_of_contacts 100

Same question as above regarding contacts. I note that there are 100 of
these things and only 60 of the other things.

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();

I doubt if you want that semicolon.

{

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;
}
}
}
******************************************************************************************************


((((SYNTAX error that i cant manage to figure out)))))

--------------------Configuration: AdressBook - Win32
Debug--------------------
Compiling...
AdressBook.c
(10) : error C2059: syntax error : 'type'
(15) : error C2059: syntax error : '}'
(18) : error C2061: syntax error : identifier 'ininfo'
(18) : error C2059: syntax error : ';'
(18) : error C2059: syntax error : 'type'
(27) : error C2065: 'contact' : undeclared identifier
(27) : error C2146: syntax error : missing ';' before identifier 'c'
(27) : error C2065: 'c' : undeclared identifier
(27) : error C2109: subscript requires array or pointer type
(28) : error C2146: syntax error : missing ';' before identifier 'tmp'
(28) : error C2065: 'tmp' : undeclared identifier
(40) : error C2109: subscript requires array or pointer type
(40) : error C2224: left of '.ininfo' must have struct/union type
(43) : error C2109: subscript requires array or pointer type
(43) : error C2224: left of '.modify' must have struct/union type
(46) : error C2065: 'contacts' : undeclared identifier
(46) : error C2146: syntax error : missing ';' before identifier 'tp'
(46) : error C2065: 'tp' : undeclared identifier
(47) : error C2143: syntax error : missing ';' before 'type'
(49) : error C2065: 'cono' : undeclared identifier
(51) : error C2109: subscript requires array or pointer type
(51) : error C2224: left of '.delete' must have struct/union type
(54) : error C2065: 'i' : undeclared identifier
(56) : error C2001: newline in constant
(57) : error C2001: newline in constant
(57) : error C2065: 's' : undeclared identifier
(57) : error C2296: '%' : illegal, left operand has type 'char [32]'
(57) : error C2143: syntax error : missing ')' before 'string'
(57) : error C2198: 'printf' : too few actual parameters
(64) : error C2146: syntax error : missing ';' before identifier
'ininfo'
(64) : warning C4013: 'ininfo' undefined; assuming extern returning int
(64) : error C2143: syntax error : missing ')' before 'type'
(64) : error C2059: syntax error : ')'
(68) : error C2065: 'temp' : undeclared identifier
(68) : error C2224: left of '.first_name' must have struct/union type
(70) : error C2224: left of '.last_name' must have struct/union type
(72) : error C2224: left of '.age' must have struct/union type
(74) : error C2224: left of '.gender' must have struct/union type
(76) : error C2224: left of '.ssn' must have struct/union type
(78) : error C2224: left of '.phone_number' must have struct/union type
(80) : error C2224: left of '.address' must have struct/union type
(85) : error C2061: syntax error : identifier 'modify'
(85) : error C2059: syntax error : ';'
(85) : error C2059: syntax error : 'type'
(115) : error C2061: syntax error : identifier 'delete'
(115) : error C2059: syntax error : ';'
(115) : error C2059: syntax error : 'type'
(137) : error C2061: syntax error : identifier 'search'
(137) : error C2059: syntax error : ';'
(137) : error C2059: syntax error : ')'
(138) : error C2449: found '{' at file scope (missing function header?)
(149) : error C2001: newline in constan
(150) : error C2001: newline in constant
(153) : error C2059: syntax error : '}'
Error executing cl.exe.

AdressBook.exe - 53 error(s), 1 warning(s)
******************************************************************************************************
 
I

Ian Collins

toch3 said:
Reposting my Question with updated code I change with forumer
guidance..with syntax error i got while run it...really appreciate for
those who willing to help me..
Observations rather than fixes:

You are missing rather a lot of semicolons. Make sure all statements,
including structure definitions and function prototypes, end in one and
you will get further.

Use decent indenting, then you will see that you have functions inside
others, not good.

If a variable name requires a comment, change it so it doesn't.

Build you program in small steps, compiling (and ideally, testing) as
you go. That way you avoid screens full of error messages.

<code snipped>
 

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,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top