1
I made a function where I pass as argument two integers and two pointers of two struct that I created in order to write the Return in a txt file.
When running the program, if I give printf()
to the function main
gives the desired value, but if fprintf()
no longer gives this value. How can I solve?
char* primeiraPessoa(int countV, int countF, Visitante *visitante, Funcionario *funcionario){
int hora=0;
char *id;
id = "N/A";
for(int i=0;i<countV;i++){
if(i==0){
sprintf(id, "%d", visitante[i].id);
hora=visitante[i].horaE;
}else if(hora>visitante[i].horaE){
sprintf(id, "%d", visitante[i].id);
hora=visitante[i].horaE;
}else if(hora==visitante[i].horaE){
strcat(id,",");
char idTemp[5];
sprintf(idTemp, "%d", visitante[i].id);
strcat(id,idTemp);
}
}
for(int i=0;i<countF;i++){
if(hora>funcionario[i].horaE){
sprintf(id, "%d", funcionario[i].id);
hora=visitante[i].horaE;
}else if(hora==funcionario[i].horaE){
strcat(id,",");
char idTemp[5];
sprintf(idTemp, "%d", funcionario[i].id);
strcat(id,idTemp);
}
}
return id;
}
To write to txt file I have the function:
void escreveFicheiro(Visitante *visitante,Funcionario *funcionario,int countV,int countF,int countInvalidas,int countBarradas){
char nome [] = "estatisticas.txt";
FILE * fp = fopen(nome, "w");
if (fp) {
fprintf(fp,"15 - %s\n",primeiraPessoa(countV,countF,visitante,funcionario));
}
fclose(fp);
}
What kind of things have been handed down to
primeiraPessoa
within thefprintf
? Also put this part in the code to make it clearer– Isac
I put the function where it is called the first Map and where are the types of the variables
– Rodrigo Marcelino
Function signature starts with 2
ints
, but you’re calling her withint
,Visitante*
– Isac
I’m sorry, I changed it a little bit and forgot to change it here too. But the error continued to give
– Rodrigo Marcelino