home *** CD-ROM | disk | FTP | other *** search
- /************** Find out the cost of stuff ***************/
- float big_cost;
-
- struct grouprec {
- int number;
- long tot_readers;
- int samp_readers;
- char *propagation;
- int traffic_msg;
- float traffic_kb;
- char *xpost;
- float cost;
- char *share;
- char *name;
- };
-
- #define MAX_NO 1000
-
- void initrec(recptr)
- struct grouprec *recptr;
- {
- recptr->propagation = (char *) malloc(7);
- recptr->xpost = (char *) malloc(5);
- recptr->share = (char *) malloc(7);
- recptr->name = (char *) malloc(50);
-
- }
- void readit(Group)
- struct grouprec *Group;
- {
- char *buffer;
- int counter;
-
- for(counter = 0; counter < MAX_NO; ) {
-
- buffer = (char *) malloc(255);
- gets(buffer);
- if(buffer[0] != '*') {
- sscanf(buffer, "%d %d %d %s %d %f %s %f %s %s",
- &Group[counter].number,
- &Group[counter].tot_readers,
- &Group[counter].samp_readers,
- Group[counter].propagation,
- &Group[counter].traffic_msg,
- &Group[counter].traffic_kb,
- Group[counter].xpost,
- &Group[counter].cost,
- Group[counter].share,
- Group[counter].name);
- big_cost += Group[counter].cost * Group[counter].tot_readers;
- counter++;
- }
- }
- }
-
- int main()
- {
- struct grouprec Group[MAX_NO]; /* This can handle MAX_NO groups */
- int counter;
- big_cost = 0;
-
- for(counter = 0; counter < MAX_NO; counter++) {
- initrec(&Group[counter]);
- }
-
- readit(Group);
- printf("Total Cost: $%f\n", big_cost);
-
- }
-