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.

Edited 3 Years Ago by happygeek: fixed formatting

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?

This article has been dead for over six months. Start a new discussion instead.