-4
I want to create a C program in which the user enters his name and this is saved permanently, but the user name is only saved until the program closes. How do I make the program to leave user data saved permanently?
-4
I want to create a C program in which the user enters his name and this is saved permanently, but the user name is only saved until the program closes. How do I make the program to leave user data saved permanently?
1
The stdio library. h has functions to create, read and write to txt files, so you can keep this data logged. 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);
}
1
You can try to create a pointer that writes in files. For 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
Browser other questions tagged c database
You are not signed in. Login or sign up in order to post.
Post your code, so it’s better to help you.
– gato
Explain better what you’re doing.
– durtto
You need to save the data in a database?
– durtto
Duplicate: http://answall.com/questions/105344/como-eu-fa%C3%A7o-o-meu-programa-em-c-ter-uma-Mem%C3%B3ria-permanente-isso-isso-%C3%A9-poss%C3%Advel
– Laerte
Be clearer. Post your code. If none of the answers given so far is accepted try to rephrase the question.
– lys