Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- typedef struct
- {
- char imie[20];
- char nazwisko[20];
- int godziny;
- int stawka;
- int premia;
- }osoba;
- void wczytywaniedanych(osoba *osoba)
- {
- printf("Podaj imie i nazwisko osoby\n");
- scanf("%s", &osoba->imie );
- scanf("%s", &osoba->nazwisko);
- printf("Podaj stawke godzinowa\n");
- scanf("%d", &osoba->godziny);
- printf("Podaj liczbe godzin\n");
- scanf("%d", &osoba->godziny);
- printf("Podaj premie\n");
- scanf("%d", &osoba->premia);
- // printf("%d",osoba->godziny);
- }
- void wyswietlanie(osoba osoba)
- {
- printf("%s %s stawka: %d",osoba.imie,osoba.nazwisko,osoba.godziny);
- }
- float obliczanko(osoba janusz)
- {
- float y;
- y=janusz.godziny*janusz.stawka *(1+janusz.premia /100.);
- printf("%f",y);
- return y;
- }
- int main()
- {
- FILE *f;
- int n=3;
- int z=1;
- osoba osoby[n];
- int rozmiar=sizeof(osoba);
- int i=0;
- int wybor;
- do{
- printf("Tworzyc, dospisac, czytac czy wyjsc?? \n");
- scanf("%d",&wybor);
- switch(wybor)
- {
- case 1:
- for(i;i<n;i++)
- {
- f=fopen("firma.txt", "wb");
- wczytywaniedanych(&osoby[i]);
- fwrite(&osoby[i],rozmiar,1,f);
- }
- fclose(f);
- break;
- case 2:
- f=fopen("firma.txt", "ab");
- wczytywaniedanych(&osoby[n+1]);
- fwrite(&osoby[n+1],rozmiar,1,f);
- fclose(f);
- break;
- case 3:
- f=fopen("firma.txt", "rb");
- int i=0;
- while(fread(&osoby[i],rozmiar,1,f)==1)
- {
- wyswietlanie(osoby[i]);
- i++;
- }
- fclose(f);
- break;
- case 4:
- printf("papa");
- fclose(f);
- break;
- default:
- printf("blad sori");
- }
- }while(wybor!=4);
- //wyswietlanie(osoba1);
- //printf("Osoba ma otrzymac %.2f ", obliczanko(osoba1));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement