Re: How to distinguish between binary and ASCII file on file opening?

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 08/14/04


Date: Sat, 14 Aug 2004 14:50:44 -0500

CFF wrote:

>I am writing an applicatioin that will need to distinguish between
>binary and ASCII file to be loaded from hard disk so that different
>processing is applied to different type of file.
>
>Is there any simple way to identify the type of file during the file
>opening process? Thank you.

ASCII is defined on character values 0-127. I think you must mean text file,
in which case, you could search a reasonably long prefix of the file (say,
the first 4-16 KB) for the char value zero, which should not appear in any
text file based on a single byte character set such as ASCII or the Windows
"ANSI".
 

-- 
Doug Harrison
Microsoft MVP - Visual C++


Relevant Pages

  • Re: Bypassing of web filters by using ASCII
    ... The character set ASCII encodes every character with 7 bits. ... Internet ... connections transmit octets with 8 bits. ...
    (Bugtraq)
  • Re: OT Brief heads-up
    ... ASCII is a character set that contains 256 items. ... I wouldn't want to predict whether Sibelius or Emacs with LilyPond would be ... If your message looks like spam I may not see it. ...
    (rec.music.early)
  • Re: extended ascii
    ... % Displays current ASCII encoding in use in Matlab ... What standard does ML use for ascii? ... text simply has to know a priori what character set to use. ...
    (comp.soft-sys.matlab)
  • Re: extended ascii
    ... % Displays current ASCII encoding in use in Matlab ... What standard does ML use for ascii? ... the character set is explicitly specified in a header. ... This is likely the character set used by the MATLAB ...
    (comp.soft-sys.matlab)
  • Re: producing junk when printing a string
    ... > He is probably not assuming ASCII. ... He more than likely knows his platform is ... > Coding for a specific character set is not a mistake. ... > foo() ...
    (alt.comp.lang.learn.c-cpp)