aboutsummaryrefslogtreecommitdiff
path: root/tests/files.cpp
blob: a07ef42b118f78782e2cc72d59ee5783f6dec1e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  FILE *file = fopen("somefile.binary", "rb");
  assert(file);

  fseek(file, 0, SEEK_END);
  int size = ftell(file);
  rewind (file);
  printf("size: %d\n", size);

  char *buffer = (char*) malloc (sizeof(char)*size);
  assert(buffer);

  size_t read = fread(buffer, 1, size, file);
  assert(read == size);

  printf("data: %d", buffer[0]);
  for (int i = 1; i < size; i++)
    printf(",%d", buffer[i]);
  printf("\n");

  fclose (file);
  free (buffer);

  fwrite("texto\n", 1, 6, stdout);
  fwrite("texte\n", 1, 6, stderr);

  return 0;
}