how do I save the data entry permanently [closed]

-4

I want to create a program in C where the user enters his name and it is saved permanently, but the user name is only saved until the program closes. How do I make the program leave user data permanently saved?

    
asked by anonymous 23.12.2015 / 18:06

2 answers

1

The stdio.h library has functions to create, read and write to txt files, so you can keep this data logged. Try to give a researched on the subject. Here is an example:

#include<stdio.h>

FILE*arquivo;
char nome[20];

int main()
{
    arquivo=fopen("exemploTXT.txt","w");
    printf("Nome: ");
    gets(nome);
    fprintf(arquivo,nome);
    fclose(arquivo);

}
    
23.12.2015 / 18:11
1

You can try to create a pointer that writes to files. To do this, try the following:

FILE *arq = fopen("endereço_do_teu_arquivo", "w"); //Esse parâmetro w significa escrita (write)

Every time you save your data to the specified file, do the following:

fprintf(arq, "%d", dado); //Isso se o dado a ser salvo for do tipo inteiro. 

At the end of the program run the command:

fclose(arq) //Este comando fecha o arquivo salvo
    
23.12.2015 / 18:37