Hi!
I had several days ago a question about converting between LabView-LabWinCVI binary files.(I have to read LabView file in LabWin).
I have my code finished, and I experianced really strange behaviour of the LabWinCVI compiled version.
Here is the ANSI-C code:
#include <ansi_c.h>
float max;
float SwapBytes (char *src) /* 4 byteos szam LabView --> LabWindows file formátum konvertere*/
{
char tmp[4];
tmp[0] = *(src + 3);
tmp[1] = *(src + 2);
tmp[2] = *(src + 1);
tmp[3] = *(src + 0);
return *(float *)tmp;
}
float fileatiro(FILE *ol)
{
float data[1];
char *raw = NULL;
raw = malloc (sizeof(float));
memset (raw, 0, sizeof(float));
fread (raw, sizeof(float), 1, ol);
data[0] = SwapBytes (raw);
free (raw);
return data[0];
}
void getMax(FILE *kk)
{
float ertek;
max = fileatiro(kk);
while (!feof(kk))
{
ertek = fileatiro(kk);
if (max < ertek ) {
max = ertek;
}
}
}
int main (int argc, char *argv[])
{ FILE *ol;
ol=fopen("aaa_z.dat", "rb");
if (ol==NULL) {
fprintf(stderr, "Sikertelen file-nyitasi kiserlet!\n");
exit(-1);
}
getMax(ol);
printf("A maximum: %f\n ", max);
fclose(ol);
//system("PAUSE");
return 0;
}
So, this code works in both DevC++ and LabWin compiled version, if i search for example in a binary file about 18kbytes, for the maximum value.
But if I use them on a binary file about 40 Mbytes, the DevC++ compiled version still working ( takes about 10 seconds to calculate
the max value) , but the LabWindows version is not ( I was waiting about half an hour, but nothing). So I just do not know why these strange results...small file works, big file doesnt?
I was trying to look for the error, and i think the LabWindows version get frozen after several thousand numbers, but i am not
sure... Why does the conventional ANSI-C compiler work, and LabWin doesnt?
Thank you for the help,
best regards,
A. B-D.