Advertisement
andruhovski

ArrayToFile_Bin

Sep 11th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5.     int N,i;
  6.     FILE *f;
  7. #ifdef _DEBUG
  8.     N=20;
  9. #else
  10.     scanf_s("%d", &N);
  11. #endif
  12.     int *mas = (int *) malloc(sizeof(int)*N);
  13.     for (i=0; i<N; i++) mas[i]=2*i+1;
  14.     fopen_s(&f,"massiv1.bin","wb");
  15.     if (f==NULL) {
  16.         printf("Error in file!");
  17.         return -1;
  18.     }
  19.     fwrite(mas,sizeof(int), N, f);
  20.     fclose(f);
  21.     printf("It's OK!\n");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement