Bifalgorithm post · Computer science one · Binary Files

How do fread and fwrite read and write binary data?

How do fread and fwrite read and write binary data? (Computer science one · Binary Files) — "22.2.2. Binary Files\n\nTo read and write binary data to files we…

Ideas in this flowchart

  • Lectura y escritura de archivos binarios
  • fread() se utiliza para leer datos binarios desde un archivo
  • fwrite() se utiliza para escribir datos binarios en un archivo
  • Ambas funciones reciben los mismos argumentos
  • ptr apunta al elemento o arreglo que se lee o escribe
  • size indica los bytes que ocupa cada elemento, normalmente mediante sizeof()
  • nmemb indica el número de elementos que se leen o escriben
  • stream identifica el flujo de archivo utilizado
  • Las funciones permiten leer o escribir una cantidad arbitraria de datos binarios
  • Al leer, ptr debe tener espacio suficiente para los datos
Feed/

How do fread and fwrite read and write binary data?

No cover

Channel

Computer science one

1 page

"22.2.2. Binary Files\n\nTo read and write binary data to files we use two different functions:\n\nsize_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);\n\nfor reading from a file and\n\nsize_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);\n\nto write to a file. Both functions have the exact same arguments:\n\n1. ptr is a pointer to the item that is being read/written (possibly an array of elements)\n\n2. size is the number of bytes that each element stored at ptr take, usually determined by using sizeof()\n\n3. nmemb is the number of elements to be written/read\n\n4. stream is the file stream to be read from/written to\n\nThese functions allow you to read/write an arbitrary amount of binary data. When reading, it is your responsibility, as usual, to ensure that the ptr is large enough to"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.