In C a structure is passed to a function by value. This means that the structure valued is copied for processing in the body of the function. Therefore any changes made to the value by the function would not give any effect on the value of the structure Any idea for me to insert the function void for this program..


#include<stdio.h>

struct book{

char title[80];
int bar_code;
float price;

};
struct book BOOK;
float price2,discount;
void main(){

struct book *ptr;
ptr = &BOOK;

clrscr();
printf("Title:");
/**scanf("%s", &ptr->title);**/
gets(ptr->title);
printf("bar code:");
scanf("%d", &ptr->bar_code);
printf("Price:");
scanf("%f", &ptr->price);

price2 = ptr->price;
if (price2>=100) {
discount =price2-(price2*0.10);

printf("discount price:%.2f",discount);
}

printf("-----------------------\n");
printf("%s\n", ptr->title);
printf("%d\n",(*ptr).bar_code);
printf("Before Discount:%.2f\n", ptr->price);
printf("After Discount:%.2f\n", discount) ;

I never give people the address to my house.

I always give them a copy of the address to my house.

They always find my house, with no problem. ;)

When you post code, use CODE tags around your code - always.

I never give people the address to my house.

I always give them a *copy* of the address to my house.

They always find my house, with no problem. ;)

When you post code, use [code] tags around your code - always.

You give them a copy of your address? Why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.