Created
May 12, 2018 03:27
-
-
Save Silva97/98763b85837317523d3011922f795707 to your computer and use it in GitHub Desktop.
This file contains 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
/******************** | |
* Exemplo por Luiz Felipe | |
* https://github.com/Silva97 | |
********************/ | |
#include <stdio.h> | |
#include <unistd.h> | |
#define FNAME "exemplo.dat" | |
typedef struct data { | |
char name[65]; | |
int age; | |
} Data; | |
int main(){ | |
Data user; | |
FILE *dat; | |
if(!access(FNAME, F_OK)){ | |
dat = fopen(FNAME, "r"); | |
fread(&user, sizeof user, 1, dat); | |
printf("Seu nome: %s\n", user.name); | |
printf("Sua idade: %d\n", user.age); | |
} else { | |
fputs("Digite seu nome: ", stdout); | |
scanf("%64[^\n]s", user.name); | |
fputs("Digite sua idade: ", stdout); | |
scanf("%d", &user.age); | |
dat = fopen(FNAME, "w"); | |
fwrite(&user, sizeof user, 1, dat); | |
} | |
fclose(dat); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment