Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Uposlenik
- {
- char ime[20];
- char prezime[20];
- int plata;
- };
- struct Uposlenik sort_po_prezimenu(struct Uposlenik niz[], int vel)
- {
- int i,j;
- char *p,*s;
- for (i=0; i<vel; i++)
- {
- for (j=i; j<vel; j++)
- {
- p=niz[i].prezime;
- s=niz[i].ime;
- if(*p > *s)
- {
- struct Uposlenik temp = niz[i];
- niz[i] = niz[j];
- niz[j] = temp;
- }
- }
- }
- };
- int main()
- {
- FILE *ulaz, *izlaz;
- int i,j, vel = 0;
- struct Uposlenik niz[10];
- char znak;
- ulaz = fopen("plata.txt", "r");
- izlaz = fopen("cp.txt", "w");
- if (ulaz == NULL)
- {
- printf("Nije moguce otvaranje datoteke..\n");
- exit(1);
- }
- if(izlaz == NULL)
- {
- printf("Nije moguce otvaranje datoreke");
- exit(2);
- }
- while(fscanf(ulaz, "%s%c%s%c%d\n", &niz[vel].ime, &znak, &niz[vel].prezime, &znak, &niz[vel].plata)!= EOF)
- {
- vel++;
- }
- sort_po_prezimenu(niz,vel);
- for (i=0; i<vel; i++)
- {
- if (niz[i].plata > 999)
- {
- fprintf(izlaz, "%s %s %d\n", niz[i].ime, niz[i].prezime, niz[i].plata);
- }
- }
- fclose(ulaz);
- fclose(izlaz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment