Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE *fp;
- fp = fopen("liczby2.dat", "a + b");
- fseek(fp, 0, SEEK_END);
- int liczbaEl = ftell(fp) / sizeof(int);
- printf("\nLiczba elementow: %d", liczbaEl);
- printf("\nElementy przed zamiana:");
- int buf, zam, zam1;
- fseek(fp, 0, 0);
- while(fread(&buf, sizeof(int),1,fp))
- printf("\n%d", buf);
- int el1, el2, k;
- printf("\nPodaj element pierwszy: ");
- scanf("%d", &el1);
- printf("\nPodaj element drugi: ");
- scanf("%d", &el2);
- fseek(fp, el1, 0);
- fread(&zam, sizeof(int), 1, fp);
- printf("\nzam = %d", zam);
- fseek(fp, el2, 0);
- fread(&zam1, sizeof(int), 1, fp);
- printf("\nzam1 = %d", zam1);
- fseek(fp, el2, 0);
- fwrite(&zam, sizeof(int), 1, fp);
- fseek(fp, el1, 0);
- fwrite(&zam1, sizeof(int), 1, fp);
- printf("\nElementy po zamianie");
- fseek(fp,0,0);
- while(fread(&buf, sizeof(int),1,fp))
- printf("\nElement: %d", buf);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement