Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     FILE *fp;
  7.     fp = fopen("liczby2.dat", "a + b");
  8.     fseek(fp, 0, SEEK_END);
  9.     int liczbaEl = ftell(fp) / sizeof(int);
  10.     printf("\nLiczba elementow: %d", liczbaEl);
  11.  
  12.     printf("\nElementy przed zamiana:");
  13.     int buf, zam, zam1;
  14.     fseek(fp, 0, 0);
  15.     while(fread(&buf, sizeof(int),1,fp))
  16.         printf("\n%d", buf);
  17.  
  18.     int el1, el2, k;
  19.     printf("\nPodaj element pierwszy: ");
  20.     scanf("%d", &el1);
  21.  
  22.     printf("\nPodaj element drugi: ");
  23.     scanf("%d", &el2);
  24.  
  25.  
  26.     fseek(fp, el1, 0);
  27.     fread(&zam, sizeof(int), 1, fp);
  28.     printf("\nzam = %d", zam);
  29.     fseek(fp, el2, 0);
  30.     fread(&zam1, sizeof(int), 1, fp);
  31.     printf("\nzam1 = %d", zam1);
  32.     fseek(fp, el2, 0);
  33.     fwrite(&zam, sizeof(int), 1, fp);
  34.     fseek(fp, el1, 0);
  35.     fwrite(&zam1, sizeof(int), 1, fp);
  36.     printf("\nElementy po zamianie");
  37.     fseek(fp,0,0);
  38.     while(fread(&buf, sizeof(int),1,fp))
  39.         printf("\nElement: %d", buf);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement