Advertisement
JCLC

Untitled

Jun 12th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5.     int *x, y = 0;
  6.  
  7.     x = (int *) malloc(sizeof(int)*4);
  8.  
  9.     for(y = 0; y < 4; y++){
  10.         x[y] = y+3;
  11.     }
  12.  
  13.     if(x == NULL){
  14.         printf("Nao foi possivel alocar memoria.");
  15.         exit(0);
  16.     }
  17.  
  18.     FILE *bin;
  19.  
  20.     bin = fopen("arquivo.bin", "wb");
  21.  
  22.     if(bin == NULL){
  23.         printf("Nao foi possivel abrir o arquivo.");
  24.         exit(0);
  25.     }
  26.  
  27.     fwrite(x, 16, 1, bin);
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement