Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. void zapis(FILE *f)
  5. {
  6. int i;
  7. srand(time(NULL));
  8. for(i=0;i<10;i++)
  9. fprintf(f,"%d\n",1+rand()%10);
  10. }
  11. void odczyt(FILE *f)
  12. {
  13. int a;
  14. while(!feof(f)) {
  15. fscanf(f,"%d",&a);
  16. if(!feof(f))
  17. printf("%d\n",a);
  18. }
  19. }
  20. int main(void)
  21. {
  22. FILE *plik;
  23. plik = fopen("test.txt","w+");
  24. if(plik == NULL) {
  25. printf("B³¹d otwarcia pliku!\n");
  26. return 0;
  27. }
  28. zapis(plik);
  29. if(fseek(plik,0,SEEK_SET)==-1) {
  30. printf("B³¹d operacji przesuwania wskaŸnika pliku!\n");
  31. return 0;
  32. }
  33. odczyt(plik);
  34. if(fclose(plik))
  35. printf("B³¹d zamkniêcia pliku!\n");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement