How we can find the given file is Binary or Text File with the help of c program?????
How we can find the given file is Binary or Text File with the help of c program?????
Well, a text-file is a binary file too - since everything stored in a computer is binary.
It is non-trivial to determine if something is text or not, but reading the file (in binary form) and scanning to see if all (or nearly all) of it's content is "printable characters", newline or carriage return would be one way.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Could you not just search for 0 bytes?
Is there a guarantee that zero bytes are always present in a binary? I don't think so. In code, yes. In the file produced by this:
It wouldn't print very well tho'.Code:int main() { unsigned char a[255]; FILE *f; for(i = 0; i < 255; i++) a[i] = i+1; f = fopen("blah.bin", "w"); fwrite(a, sizeof(a), 1, f); fclose(f); }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
As said before all files are binary file. It totally depends on how do u open a file. So for example if can create a text file with some text. And you can open the same text file in binary to in a text.
But if you create a binary file and open in a text mode, may be u wont recognize those chars. Since it might all me random chars. It up you on how u open the file and how u interpret the values in the file.
ssharish
>How we can find the given file is Binary or Text File with the help of c program?????
Binary or text are C's way of knowing how to properly buffer characters for you. That's it. The data coming in is binary, and the data going out is binary. In the middle you might get textual conversions like CRLF to LF (and vice versa). Since the difference is only relevant within your program, and your program opened the file, you already know what the open mode was.
My best code is written with the delete key.