Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #define MAX_SIZE 20+1
- struct zelja_st{
- double broj_gostiju;
- char naziv_pice[MAX_SIZE];
- };
- struct porudzbina_st{
- double broj_potrebnih_parcadi;
- double broj_potrebnih_pica;
- char naziv_pice[MAX_SIZE];
- };
- FILE*safe_fopen(char filename[],char mode[],int error_code);
- void ucitavanje_strukture(FILE*in,struct zelja_st zelja[],int *n);
- double broj_potrebnih_parcadi(struct zelja_st zelja,double apetit);
- double broj_potrebnih_pica(struct zelja_st zelja,double apetit);
- void transform(struct zelja_st zelja[],struct porudzbina_st porudzbina[],int n,double apetit);
- void snimi_porudzbine(FILE *out, struct porudzbina_st porudzbine[], int n) ;
- int main(int arg_num,char **args);
- if (arg_num != 4){
- printf("File:%s can not be opened",args[0]);
- error(404);
- }
- double apetit=atof(args[1]);
- char *in_filename=args[2];
- char *out_filename=args[3];
- FILE*in=safe_fopen(in_filename,"r",1);
- FILE*out=safe_fopen(out_filename,"w",2);
- struct zelja_st;
- struct porudzbina_st;
- ucitavanje_strukture(in,zelja,&n);
- broj_potrebnih_parcadi(zelja,apetit);
- broj_potrebnih_pica(zelja,apetit);
- transform(zelja,porudzbina,n,apetit);
- snimi_porudzbine(out,porudzbine,n);
- int n;
- fclose(in);
- fclose(out);
- return 0;
- }
- FILE*safe_fopen(char filename[],char mode[],int error_code){
- char *fp=fopen(filename,mode);
- if (fp==NULL){
- printf("File %s can not be opened",filename);
- exit(error_code);
- }
- return fp;
- }
- void ucitavanje_strukture(FILE*in,struct zelja_st zelja[],int *n){
- *n=0;
- while (scanf(in,"%lf %s",
- &zelja[*n].broj_gostiju,
- zelja[*n].naziv_pice) !=EOF){
- (*n)++;
- }
- double broj_potrebnih_parcadi(struct zelja_st zelja,double apetit){
- broj_potrebnih_parcadi=zelja.broj_gostiju*apetit;
- return broj_potrebnih_parcadi;
- }
- double broj_potrebnih_pica(struct zelja_st zelja,double apetit){
- broj_potrebnih_pica=broj_poterbnih_parcadi(zelja,apetit)/8;
- return broj_potrebnih_pica;
- }
- void transform(struct zelja_st zelja[],struct porudzbina_st porudzbina[],int n,double apetit){
- int i;
- for(i=0;i<n;i++){
- strcpy(porudzbina[i].naziv_pice,zelja[i].naziv_pice);
- porudzbina[i].broj_potrebnih_parcadi=broj_potrebnih_parcadi(zelja[i],apetit);}
- }
- void snimi_porudzbine(FILE *out, struct porudzbina_st porudzbine[], int n) {
- int i;
- for(i=0; i<n; i++) {
- fprintf(
- out, "%5.1f %2u %s\n",
- porudzbine[i].broj_parcadi,
- porudzbine[i].broj_celih_pizza,
- porudzbine[i].pizza
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement