Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do i write a C program including necessary functions to convert a binary file to a text file.

+1 vote
asked May 16, 2020 by Toluwani Babalola (130 points)

1 Answer

0 votes
answered Jun 5, 2020 by Peter Minarik (86,160 points)

This question is not specific enough.

What do you mean by binary and text file?

In my interpretation there are only files. You can open any file in a text editor (even an executable file, though probably you don't want to open large files in text editors as it may be slow).

On the other hand, you can open a file in binary or text mode. In text mode you can write only characters in the file. In binary mode, you can write bytes.

Sure, an ANSI character can be translated as a byte, so an ANSI text is more or less indistinguishable if you read it as text or binary data.

On the other hand, if you want to store the number e.g. 100, it would take only one byte (in binary mode), which looks like 'd' in a text editor; but in text mode, it would take "100" to store this, which is 3 bytes.

Also, text files have easy syntax and interpretation: everything is a character. You're reading a text.

For binary files, you need to know what you're reading. You need to know structure of your records. How many bytes belong together? Are they represent an integral number? A floating point number? A character? Or maybe a logical value? (Or something else?)

Hence converting a binary data to text data is impossible, unless you know the structure of the binary, the records that are written there.

So again, what are you after? One would need more specifics.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...