Concept
How do you write and read binary data in C?
ComputerScienceOne / Closing Files
"int x = 10;\n\nFILE *binaryOutputFile = fopen(\"demo.bin\", \"w\");\n\n//write a single int to a file:\n\nfwrite(&x, sizeof(int), 1, binaryOutputFile);\n\nFILE *binaryInputFile = fopen(\"input.bin\", \"r\");\n\n//read a single int from the file:\n\nfread(&x, sizeof(int), 1, binaryInputFile);\n\n//read an entire array from the file:\n\nint *a = (int *) malloc(10 * sizeof(int));\n\nfread(a, sizeof(int), 10, binaryInputFile);"
Related Ideas
- How do fread and fwrite read and write binary data?ComputerScienceOne · Binary Files
- When should data be stored as binary or text files?ComputerScienceOne · Buffered and Unbuffered
- How do fprintf() and fscanf() read from and write to plaintext files?ComputerScienceOne · Plaintext Files
- How are files read, written, and properly managed?ComputerScienceOne · Paths
- What is 22?ComputerScienceOne · Opening Files
- How do buffered and unbuffered file input/output differ?ComputerScienceOne · Buffered and Unbuffered
- What types of errors can occur when processing files?ComputerScienceOne · Error Handling
- How can you read a text file one line at a time?ComputerScienceOne · Binary Files