Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. #define MAX_SIZE 20+1
  7.  
  8. struct zelja_st{
  9.     double broj_gostiju;
  10.     char naziv_pice[MAX_SIZE];
  11. };
  12. struct porudzbina_st{
  13.     double broj_potrebnih_parcadi;
  14.     double broj_potrebnih_pica;
  15.     char naziv_pice[MAX_SIZE];
  16. };
  17. FILE*safe_fopen(char filename[],char mode[],int error_code);
  18. void ucitavanje_strukture(FILE*in,struct zelja_st zelja[],int *n);
  19. double broj_potrebnih_parcadi(struct zelja_st zelja,double apetit);
  20. double broj_potrebnih_pica(struct zelja_st zelja,double apetit);
  21. void transform(struct zelja_st zelja[],struct porudzbina_st porudzbina[],int n,double apetit);
  22. void snimi_porudzbine(FILE *out, struct porudzbina_st porudzbine[], int n) ;
  23.  
  24. int main(int arg_num,char **args);
  25.  
  26.     if (arg_num != 4){
  27.         printf("File:%s can not be opened",args[0]);
  28.         error(404);
  29.         }
  30.     double apetit=atof(args[1]);
  31.     char *in_filename=args[2];
  32.     char *out_filename=args[3];
  33.     FILE*in=safe_fopen(in_filename,"r",1);
  34.     FILE*out=safe_fopen(out_filename,"w",2);
  35.     struct zelja_st;
  36.     struct porudzbina_st;
  37.     ucitavanje_strukture(in,zelja,&n);
  38.     broj_potrebnih_parcadi(zelja,apetit);
  39.     broj_potrebnih_pica(zelja,apetit);
  40.     transform(zelja,porudzbina,n,apetit);
  41.     snimi_porudzbine(out,porudzbine,n);
  42.  
  43.    
  44.     int n;
  45.  
  46.     fclose(in);
  47.     fclose(out);
  48. return 0;
  49. }
  50.  
  51. FILE*safe_fopen(char filename[],char mode[],int error_code){
  52.     char *fp=fopen(filename,mode);
  53.     if (fp==NULL){
  54.         printf("File %s can not be opened",filename);
  55.         exit(error_code);
  56.         }
  57. return fp;
  58. }
  59. void ucitavanje_strukture(FILE*in,struct zelja_st zelja[],int *n){
  60.     *n=0;
  61.     while (scanf(in,"%lf %s",
  62.             &zelja[*n].broj_gostiju,
  63.             zelja[*n].naziv_pice) !=EOF){
  64.             (*n)++;
  65.             }
  66. double broj_potrebnih_parcadi(struct zelja_st zelja,double apetit){
  67.     broj_potrebnih_parcadi=zelja.broj_gostiju*apetit;
  68. return broj_potrebnih_parcadi;
  69. }
  70. double broj_potrebnih_pica(struct zelja_st zelja,double apetit){
  71.     broj_potrebnih_pica=broj_poterbnih_parcadi(zelja,apetit)/8;
  72. return broj_potrebnih_pica;
  73. }
  74. void transform(struct zelja_st zelja[],struct porudzbina_st porudzbina[],int n,double apetit){
  75.     int i;
  76.     for(i=0;i<n;i++){
  77.         strcpy(porudzbina[i].naziv_pice,zelja[i].naziv_pice);
  78.         porudzbina[i].broj_potrebnih_parcadi=broj_potrebnih_parcadi(zelja[i],apetit);}
  79. }
  80. void snimi_porudzbine(FILE *out, struct porudzbina_st porudzbine[], int n) {
  81.     int i;
  82.     for(i=0; i<n; i++) {
  83.         fprintf(
  84.             out, "%5.1f %2u %s\n",
  85.             porudzbine[i].broj_parcadi,
  86.             porudzbine[i].broj_celih_pizza,
  87.             porudzbine[i].pizza
  88.         );
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement