Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(void){
  7.     FILE *pFile;
  8.     char *temp, c;
  9.     int dlugosc;
  10.     int i=0;
  11.     pFile = fopen("Baza_studentow.bin","rb");
  12.     if(!pFile){
  13.         printf("error opening file!\n");
  14.         exit(0);
  15.     }else{
  16.         fseek(pFile,0,SEEK_END);
  17.         dlugosc = ftell(pFile);
  18.         rewind (pFile);
  19.         temp = malloc(sizeof(char)*dlugosc);
  20.         if(!temp){
  21.             printf("Brak pamieci");
  22.             exit(0);
  23.         }
  24.         fread(temp,sizeof(char),dlugosc/sizeof(char),pFile);
  25.         fclose(pFile);
  26.     }
  27.     pFile = fopen("Nowy.bin","wb");
  28.     if(!pFile){
  29.         printf("error opening file!\n");
  30.         exit(0);
  31.  
  32.     }else{
  33.         fwrite(temp,sizeof(char),dlugosc/sizeof(char),pFile);
  34.         fclose(pFile);
  35.     }
  36.     pFile = fopen("Nowy.bin","rb");
  37.     if(!pFile){
  38.         printf("error opening file!\n");
  39.         exit(0);
  40.     }else{
  41.         c = fgetc(pFile);
  42.         while (c != EOF)
  43.         {
  44.             printf ("%c", c);
  45.             c = fgetc(pFile);
  46.         }
  47.         fclose(pFile);
  48.     }
  49.     free(temp);
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement