Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //Napisati C program koji će kreirati datoteku kupci.dat. Program treba omogućiti upisivanje sljedećih
  2. //podataka: ime, prezime, adresa i broj telefona svih kupaca neke tvrtke za uvoz.
  3.  
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6.  
  7. int main(){
  8. struct podaci {
  9. char ime[20], prezime[20], adresa[40];
  10. int tel;
  11. } kupac;
  12. int i, n;
  13. FILE *f;
  14. f=fopen("kupci.dat","w");
  15. if(f==NULL){
  16. printf("\nGreska pri otvaranju\n");
  17. return 1; }
  18. puts("\nKoliko ima kupaca?\n");
  19. scanf("%d", &n);
  20. for(i=1; i<=n; i++){
  21. printf("upisi podatke za %d. kupca: \n", i);
  22. printf("\nime: ");
  23. scanf("%s", kupac.ime);
  24. printf("\nprezime: ");
  25. scanf("%s", kupac.prezime);
  26. printf("\nadresa: ");
  27. scanf("%s", kupac.adresa);
  28. printf("\ntelefon: ");
  29. scanf("%d", &kupac.tel);
  30. fwrite(&kupac, sizeof(struct podaci),1,f); }
  31. fclose(f);
  32. system("pause");
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement