fread() in MATLAB and C

6 vues (au cours des 30 derniers jours)
Pravitha A
Pravitha A le 14 Fév 2020
Commenté : Pravitha A le 14 Fév 2020
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??

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Fév 2020
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.
  1 commentaire
Pravitha A
Pravitha A le 14 Fév 2020
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by