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?
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?
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);
}
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