I want to multiply two different structures in c language -


i'm student of bs computer science. working on inventory system first project me uni. facing 1 problem while working on ending inventory. want add opening , purchase , subtract sell it.. unable so. please me solve issue.

consider structure:

struct inventory {     char id[10];     char item[20];     int  quant;     int cost; } data[20], data1[20]; 

now, go through store , inventory of stuff , go through warehouse , inventory. want total inventory (data , data1). can following, including printouts:

int total; (i = 0; < 20; i++) {     total = data[i].quant + data1[i].quant;     printf("item %s, id %s: ", data[i].item, data[i].id);     printf("store: %5d  warehouse: %5d  total: %6d\n",            data[i].quant, data1[i].quant, total) } 

so, total total 2 structures (i assuming ith element of each data array same items - should check before printout). printout occur on 1 line (because there no \n @ end of first printf).

now, if want manipulate elements of structure, simple. consider:

struct items {     int opening, purchase, sell; } element;  int remaining; // calculate remaining items: remaining = element.opening + element.purchase - element.sell;  // ... <other processing> // printouts, etc. information // ...  // update structure next cycle. element.opening  = remaining; element.purchase = 0; element.sell     = 0; 

this example shows manipulating elements of structure. can use function same thing , pass pointer structure. more flexible since doesn't care or know how many different inventory items have:

int getremaining(struct items *item) {     int remaining;     remaining = item->open + item->purchase - item->sell;     item->open = remaining;     item->purchase = 0;     item->sell     = 0;     return remaining; } 

and there go - way access structure elements across multiple instances of structure , way access , manipulate elements within structure.

good luck


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -