Advertisement
LegoDrifter

Untitled

Jan 20th, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. // ne menuvaj ovde
  5. void wf() {
  6. FILE *f = fopen("livce.txt", "w");
  7. char c;
  8. while((c = getchar()) != '#') {
  9. fputc(c, f);
  10. }
  11. fclose(f);
  12. }
  13.  
  14.  
  15. int main() {
  16. wf();
  17. // vasiot kod ovde
  18.  
  19. int uplata, tip;
  20. int max_tip;
  21. char max_sifra[10];
  22. char sifra[10];
  23.  
  24. float koef, max_koef, dobivka = 1;
  25.  
  26. FILE *f = fopen("livce.txt", "r");
  27.  
  28. if (!f){
  29. printf("Can not open file livce.txt");
  30. exit(-1);
  31. }
  32.  
  33.  
  34. //printf("AAA");
  35.  
  36. fscanf(f, "%d", &uplata);
  37.  
  38. if (fscanf(f, "%s %d %f", max_sifra, &max_tip, &max_koef)&&!feof(f)){
  39.  
  40. dobivka = uplata*max_koef;
  41.  
  42. while(fscanf(f, "%s %d %f", sifra, &tip, &koef)==3) {
  43.  
  44. dobivka *= koef;
  45.  
  46. if (koef > max_koef){
  47. strcpy(max_sifra, sifra);
  48. max_tip = tip;
  49. max_koef = koef;
  50. }
  51.  
  52. }
  53.  
  54. printf("%s %d %.2f\n%.2f", max_sifra, max_tip, max_koef, dobivka);
  55. }
  56.  
  57. fclose(f);
  58. return 0;
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement