MATLAB: Fread() in MATLAB and C

fread

Is fread() in MATLAB and C different? I have a command
offset = fread(fd, 1, 'uint32');
Can I directly use this comman in a C program. WOuld it give the same result??

Best Answer

Is fread() in MATLAB and C different?
Yes
Can I directly use this comman in a C program. WOuld it give the same result??
No, it would be an error in multiple ways.
In C, the first parameter would need to be the address of the buffer to put the data into, cast to (void *). The second parameter would be the size of each element in bytes, which for uint32 would be 4 (that is, 4 bytes.) The third parameter would be the count of the number of items to read, which would be 1 for your example.
The 4th parameter needs to be the stream pointer that resulted from an fopen() (or one of some more obscure library calls). Stream pointers in C and C++ are not integers. The integers that you see in MATLAB are much closer to C's "file descriptors", and if you mix up the two then you will get an compiling error or you will get a crash.
Related Question