Opening a Binary File in Command

  • Thread starter Thread starter dudforreal
  • Start date Start date
  • Tags Tags
    Binary File
AI Thread Summary
To open a binary file in Pelles C, the correct method is to use fopen with the "rb" mode, which allows reading binary files. The example code provided successfully opens a binary file and reads data into an array of Car_t structures. However, binary files are not human-readable, unlike flat files, which can be directly viewed. The user is experiencing issues with the program not functioning as expected when attempting to read from the binary file. The discussion emphasizes that the problem may lie elsewhere in the code, rather than in the file opening method itself.
dudforreal
Messages
116
Reaction score
0
How do you open a binary file in command in Pelles C so that it is readable?
 
Technology news on Phys.org
I would check if fopen("filename","rb") is not working.
 
Borek said:
I would check if fopen("filename","rb") is not working.

fopen is working
Code:
void readFleet(Car_t toRead[])
{
    FILE *fFleet;
    fFleet = fopen("Fleet_File.bin", "rb");
    fread(toRead, 10*sizeof(Car_t), 1, fFleet);
    fclose(fFleet);
}
 
My program on Pelles C is creating a binary file when I want the results to save to a file but I'm not sure on how to open the binary file in cmd in Pelles C so that it is readable and I can read it.
 
dudforreal said:
How do you open a binary file in command in Pelles C so that it is readable?

"binary file" generally denotes a file that is NOT readable directly by humans, if that's what you mean. A file that is directly readable by humans is called a "flat file".
 
I have 6 options in my code and it does create a binary file in my project folder when I press 4 but when I press 5 it doesn't work.

Code:
printf("1. Add a car to the fleet.\n");
printf("2. Delete last car from the fleet.\n");
printf("3. Display full fleet on the screen.\n");
printf("4. Save the fleet to a file.\n");
printf("5. Read the fleet from a file.\n");
printf("0. Exit the program\n");
printf("\nPlease enter your choice:\n\n");
 
What you just did is you have showed a mechanic the ignition key, and asked why your car is not starting. Zillions of things that can be wrong, the way your menu looks has probably nothing to do with any of them.
 

Similar threads

Replies
57
Views
5K
Replies
2
Views
770
Replies
33
Views
2K
Replies
10
Views
5K
Replies
20
Views
3K
Replies
9
Views
3K
Replies
12
Views
11K
Replies
4
Views
1K
Back
Top