Re: The infamous ^Z problem




"Old Wolf" <oldwolf@xxxxxxxxxxxxxx> wrote in message
news:1179887442.573804.42410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 23, 12:34 pm, "Eigenvector" <m44_mas...@xxxxxxxxx> wrote:
if ( (infile = fopen(argv[1], "rb") == NULL) /*picked the binary part
up
from this google group*/
{
printf("Cannot open file\n");
exit(1);
}
if ( (outfile = fopen("Clean_file", "w+")) == NULL)

Open mode should be "w+b". You want to write it the
same way you read it.

if(c == 0x1a) /* This is where I'm having a problem */
/* if(c == '\0x1a') This fails with compiler error - more than
one
character defined for type char */

There are four characters in that constant: '\0', 'x',
'1', and 'a'. I think you mean '\x1a', although the
uncommented code is also correct and does the same thing.

Yeah it's a pretty primitive code, but I'm more interested in getting the
basics working before I go in and optimize the way it handles the input
file. This compiles on xlC and HP's ANSI C compilers.

Out of interest, how were you planning on optimising
this? (I think you'll find that reading in a block
at a time won't gain you anything).

In the first if statement dealing with the ^Z, the program doesn't detect
the control characters in the file, in the second statement the compiler
complains about syntax. If I set c as typecast char, it finds the
control
characters, replaces them, but then blows away the EOF character and
nukes
the file.

It doesn't seem possible that your posted code won't
find the 0x1a characters. There must be some other
problem, e.g. this isn't your real code, or the
non-binary output is munging up.

This is the real code, albeit definitely primitive. I would have thought it
would have found the ^Zs too, but on a SINGLE platform it doesn't. I trust
that the platform is ANSI compliant, so that tells me that my problems lie
with the code ultimately.


I can't find any good consistent documentation on exactly
how to represent hex or octal in c code or string/character
operations.

Try the C Standard, or "The C Programming Language"
by Kernighan & Ritchie.



.



Relevant Pages

  • Re: Upgrade to 8.14.2 stops automatic MIME conversion to 8-bit
    ... I've confirmed that the same issue applies to my compiles of 8.14.3. ... it on Solaris 8 Sparc and Solaris 10 x86. ... then those characters could be ...
    (comp.mail.sendmail)
  • Re: Damn you, FEDEX! or Nikon D40 lost in Springfield, MO blackhole.
    ... the 2 mp Mavica he had been using with a Nikon D40. ... After shopping around, he got me to order one for him. ... The shipper had it insured, but from what I have read it could take weeks to sort this crap out. ... You may get your insurance from FedEx and a couple weeks later they find it and deliver it. ...
    (alt.photography)
  • Re: The infamous ^Z problem
    ... Open mode should be "w+b". ... This compiles on xlC and HP's ANSI C compilers. ... the control characters in the file, in the second statement the compiler ... it would have found the ^Zs too, but on a SINGLE platform it doesn't. ...
    (comp.lang.c)
  • Re: Umlaut in identifier
    ... > characters. ... > So this code is Standard compliant: ... > The first example compiles in vc 7.1 the latter not: ... I'm Schobi at suespammers dot org ...
    (microsoft.public.vc.language)
  • Re: The infamous ^Z problem
    ... Open mode should be "w+b". ... This compiles on xlC and HP's ANSI C compilers. ... the control characters in the file, in the second statement the compiler ...
    (comp.lang.c)