Q

How do I check whether a file is a text file or binary file using C/C++?

How do I check whether a file is a text file or binary file using C/C++?
Probably the easiest way is to use the C Run Time function, isprint. That will determine if a byte is a printable character. As you scoot through the file, as soon as you find a byte that's not printable, you can probably safely assume it's not a text file. Of course, if you want to allow UNICODE text files, you'll have to do much more work, which is not fool proof.
This was first published in September 2002

Dig deeper on Windows Operating System Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close