Hi all,
I'm quite a beginner in C programming. After some time working perfectly, it seems to be an error (Illegal Instruction) when writing a file using fprintf. It has taken a lot of time, so I decided to post it. Here is the code:
Code:
void calculateMeanTimes(long t_init, long t_rx, long t_proces, long t_proces_max, int frames){
FILE * time_file;
float mean_rx;
float mean_proces;
float time_init;
float time_proces_max;
time_init = ((float)t_init)/1000000.0;
time_proces_max = ((float)t_proces_max)/1000000.0;
mean_rx = (((float)t_rx)/1000000.0)/frames;
mean_proces = (((float)t_proces)/1000000.0)/frames;
/* Escritura de los datos en el fichero*/
time_file=fopen("temporizacion.dat","w");
if (time_file==NULL)
syslog(LOG_ERR,"Error en prueba de temporización al abrir fichero temporizacion.dat\n");
fprintf(time_file,TIME_HEADER);
fprintf(time_file,"\n");
fprintf(time_file,"Tiempo de inicializacion (Procesado de primera trama: %f\n",time_init);
fprintf(time_file,"Numero de tramas computadas para calcular media y tiempo maximo: %d\n",frames);
fprintf(time_file,"Tiempo medio de recepcion: %f\n",mean_rx);
fprintf(time_file,"Tiempo medio de procesado: %f\n",mean_proces);
fprintf(time_file,"Tiempo medio de total: %f\n",mean_rx + mean_proces);
fprintf(time_file,"Tiempo maximo de procesado: %f\n",time_proces_max);
fprintf(time_file,"******************************************");
fclose(time_file);
}
When I comment any "fprintf line" it works (sure it does not do anything, but the programs doesn't throw any error), so it seems to be that the problems arises from the writing commands.
I'd appreciate any suggestion.
Thanks in advance!!!
G.