Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #define MAXL 20
- int racun (int c) /* izracunavanje broja potrebnih pica, jedna pica je
- 8 parcadi, a potrebne su 2.5 pica po coveku u proseku, potreban je ceo broj pica*/
- {
- float brP;
- int brPr;
- brP = c * 2.5;
- // ovo je neki moj nacin za izracunavanje celobrojne vrednosti, vrv postoji neki laksi nacin
- if (((float)brP/8) > ((int)brP/8))
- {
- brPr = (int)brP/8 + 1;
- }
- if (((float)brP/8) == ((int)brP/8))
- {
- brPr = (int)brP/8;
- }
- return brPr;
- }
- int main (int brArg, char *arg[])
- {
- char imeP [MAXL]; //ime pice
- int brLj; // broj ljudi koji ce jesti picu
- int brP; // broj pica koja je potrebna
- FILE *in; // provera ulaznog fajla
- if((in = fopen(arg[1], "r")) == NULL)
- {
- exit(1);
- }
- FILE *out; // provera izlaznog fajla
- if((out = fopen(arg[2], "w")) == NULL)
- {
- exit(2);
- }
- while((fscanf(in, "%2d%s", &brLj, imeP))!=EOF)
- {
- brP = racun(brLj);
- fprintf(out, "%2d %s\n", brP, imeP);
- }
- fclose(in);
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement