Created
May 11, 2011 03:27
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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