So my problem is: I need to get some primitive values(floats) from a file I used and parsed in Java to my C code(testing between Java and C implementation). So in Java I used ByteBuffer.allocate()
to get bytes and Files.write()
to write them in the file. File looks OK, I checked him with Hex Editor(real values, not just zero's). Now in C, for reading the data I used:
float * floatArray = malloc(numData * sizeof(float)); //numData is int, 1000 for example
FILE * stream = fopen(input, "rb"); //input is the name of my binary file
rewind(stream);
fread(floatArray, numData, sizeof(float), stream);
fclose(stream);
and for test:
for(i = 0; i < 128; i++) {
printf("%f, ", floatArray[i]);
}
but only thing I see is
0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, + next 114 zeros
For more details:
Input file has like 158 MB. It actually has lot of zeros in it, but for example, first 3 numbers should be 9, 52 and 29. Another thing is that I already checked the return value of fread
and it returns the right value (numData). I checked other questions on the site but I didn't really found my problem. Other ones had problems like they set file indicator with fseek
at the end of the file when they got all the zero's. I guess it can't be endianess problem too because I think I would get bad values and not zero's only. I use Visual C++ 2008 Express edition on Windows 7.
Sorry for my formatting and english, it's my first question. I'll be thankfull for any kind of help.