Created
May 25, 2019 19:10
-
-
Save pxpc2/a6e8f3b67ed48259758505e499cc19e7 to your computer and use it in GitHub Desktop.
drezin
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| void criarRegistro(FILE *arq) | |
| { | |
| arq = fopen("dados.txt", "a"); | |
| if (arq == NULL) | |
| { | |
| printf("Deu ruim\n"); | |
| return; | |
| } | |
| int conta; | |
| char nome[31]; | |
| double saldo; | |
| printf("Entre com o número da sua conta\n"); | |
| scanf("%d", &conta); | |
| printf("Entre com seu nome\n"); | |
| scanf("%s", nome); | |
| printf("Entre com o saldo da conta\n"); | |
| scanf("%lf", &saldo); | |
| fprintf(arq, "%s\n%d\n%.2lf\n", nome, conta, saldo); | |
| fclose(arq); | |
| } | |
| void lerRegistro(FILE *arq) | |
| { | |
| arq = fopen("dados.txt", "r"); | |
| if (arq == NULL) | |
| { | |
| printf("Deu ruim\n"); | |
| return; | |
| } | |
| int numRegistro; | |
| printf("Entre com o número do registro\n"); | |
| scanf("%d", &numRegistro); | |
| char linha[32]; | |
| int count = 0, count2 = 0; | |
| while (fgets(linha, 32, arq) != NULL) | |
| { | |
| if (count2 == 3) break; | |
| if (count != (numRegistro-1) * 3) | |
| { | |
| count++; | |
| continue; | |
| } | |
| printf("%s", linha); | |
| count2++; | |
| } | |
| } | |
| int main() | |
| { | |
| FILE *arq; | |
| while (1) | |
| { | |
| printf("Entre com sua opção\n" | |
| "0: Sair do programa\n" | |
| "1: Criar novo registro\n" | |
| "2: Ler registro já cadastrado\n"); | |
| int opcao; | |
| scanf("%d", &opcao); | |
| switch (opcao) | |
| { | |
| case 0: | |
| printf("Obrigado!\n"); | |
| return 0; | |
| case 1: | |
| criarRegistro(arq); | |
| break; | |
| case 2: | |
| lerRegistro(arq); | |
| break; | |
| default: | |
| printf("Entre com uma opção válido kraio\n"); | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment