0
Good morning. I have a problem to be able to create a file that stores the time when the user modified a particular program, for example: If the user ran the file at 2h34min32s, I want to save this date in a file with this format"cliente_2_34_32.txt". the cogido is below:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct cliente{
char nome[30];
int cpf,cep;
};
void info(struct cliente *aux){
int cpf,cep;
printf("\n digite os dados:\n Nome:");
gets(aux->nome);
printf("\n CPF: ");
scanf("%d",&cpf);
fflush(stdin);
printf("\n CEP: ");
scanf("%d",&cep);
fflush(stdin);
aux->cpf=cpf;
aux->cep=cep;
};
int main()
{
time_t tempo;
struct tm *tempoS;
int n=0;
struct cliente *vet,*aux;
FILE *ptr;
vet=(struct cliente*)malloc((n+1)*sizeof(struct
cliente));
info(vet);
int v,y=1;
while(y){
printf("\n Deseja continuar: 1- sim, outro numero-
nao");
scanf("%d",&v);
fflush(stdin);
if(v==1){
n++;
vet=(struct cliente*)realloc(vet,(n+1)*sizeof(struct cliente));
aux=&vet[n];
info(aux);
}else{
y=0;
}
}
free(vet);
tempo=time(NULL);
tempoS=localtime(&tempo);
char nome[]="vaca_%d.txt";
printf("cliente_%d_%d_%d",tempoS->tm_hour,tempoS->tm_min,tempoS->tm_sec);
ptr=fopen(nome,"w");
fclose(ptr);
return 0;
}
I wanted to know how to make the printf phrase (cliente_17_14_43) be the name of the txt file.
What happens when you run the cogido? Does it give an error? If it does, already edit the question and describe it. If it does not give error, already edits the question and describes what is the observed behavior. What was the answer? What should it be? Does it even create the file? With what name?
– Woss