Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STructure

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
hi,
is it possible to declare a structure as a reference parameter?
If it does, may I know why the following codes of mine
is wrong?


//initialisation
struct book_record
{
char ISBN[11];
char title[31];
char author[31];
char category[3];
char date[11];
float price;
};

struct BkArray
{
struct book_record BookArray[10];
};




void add_records(BkArray *library)
{
//variables
int number;

printf("\nEnter the number of records that you are going to enter: ");
scanf("%d", &number);

for(int k = 0; k < number; k++)
{
printf(&quot;\n#%d Record:\n&quot;, k+1);
BarLine(30);
printf(&quot;Enter ISBN: &quot;);

gets( library.BookArray[k].ISBN);
printf(&quot;\nEnter the title of the book: &quot;);
gets( library.BookArray[k].title);
printf(&quot;\nEnter the author of the book: &quot;);
gets(library.BookArray[k].author);
printf(&quot;\nEnter the price of the book: &quot;);
scanf(&quot;%f&quot;, &library.BookArray[k].price);
printf(&quot;\nEnter the category of the book\n&quot;);
gets( library.BookArray[k].category);
printf(&quot;\nEnter the published date in the format of dd/mm/yyyy: &quot;);
gets (library.BookArray[k].date);
}//for
}//add_records
 
you should use &quot;library->&quot; instead of &quot;library.&quot; because &quot;library&quot; is a pointer.
 
Also, skiping word struct in
void add_records(BkArray *library)
at least in ANSI C.

 
hi,

I have changed to library-> but there are still errors saying: Cannot convert
'BkArray' to 'BkArray *' in function main() and Type mismatch in parameter 'library'
in call to 'add_records(BkArray *)' in function main().

Additional code:

struct book_record
{
char ISBN[11];
char title[31];
char author[31];
char category[3];
char date[11];
float price;
};

struct BkArray
{
struct book_record BookArray[10];
};

//function prototypes
void add_records(BkArray *library);
void display_all_records(BkArray *library);
void display_information(char *IBSN, BkArray *library);
void display_books(BkArray *library);
void delete_records(char *title, BkArray *library);
void BarLine(int num);

switch(choice)
{
case 1: add_records(library);
break;
:
:

void add_records(BkArray *library)
{
//variables
int number;

printf(&quot;\nEnter the number of records that you are going to enter: &quot;);
scanf(&quot;%d&quot;, &number);

for(int k = 0; k < number; k++)
{
printf(&quot;\n#%d Record:\n&quot;, k+1);
BarLine(30);
printf(&quot;Enter ISBN: &quot;);

gets( library->BookArray[k].ISBN);
printf(&quot;\nEnter the title of the book: &quot;);
gets( library->BookArray[k].title);
printf(&quot;\nEnter the author of the book: &quot;);
gets(library->BookArray[k].author);
printf(&quot;\nEnter the price of the book: &quot;);
scanf(&quot;%f&quot;, library->BookArray[k].price);
printf(&quot;\nEnter the category of the book\n&quot;);
gets( library->BookArray[k].category);
printf(&quot;\nEnter the published date in the format of dd/mm/yyyy: &quot;);
gets (library->BookArray[k].date);
}//for
}//add_records

May I know what is wrong at the switch statement?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top