Skip to content

Instantly share code, notes, and snippets.

@carlosbrando
Created May 11, 2011 03:27
Show Gist options
  • Save carlosbrando/965865 to your computer and use it in GitHub Desktop.
Save carlosbrando/965865 to your computer and use it in GitHub Desktop.
Escreve alguns dados não-caracteres em um arquivo em disco e lê de volta.
/* Escreve alguns dados não-caracteres em um arquivo em disco
* e lê de volta. */
#include <stdio.h>
#include <stdlib.h>
main(void) {
FILE *fp;
double d = 12.23;
int i = 101;
long l = 123023L;
if ((fp = fopen("test", "wb+")) == NULL) {
printf("O arquivo não pode ser aberto.\n");
exit(1);
}
fwrite(&d, sizeof(double), 1, fp);
fwrite(&i, sizeof(int), 1, fp);
fwrite(&l, sizeof(long), 1, fp);
rewind(fp);
fread(&d, sizeof(double), 1, fp);
fread(&i, sizeof(int), 1, fp);
fread(&l, sizeof(long), 1, fp);
printf("%f %d %ld\n", d, i, l);
fclose(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment