Re: The infamous ^Z problem
- From: "Eigenvector" <m44_master@xxxxxxxxx>
- Date: Tue, 22 May 2007 20:28:25 -0700
"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.
.
- Follow-Ups:
- Re: The infamous ^Z problem
- From: Joachim Schmitz
- Re: The infamous ^Z problem
- References:
- The infamous ^Z problem
- From: Eigenvector
- Re: The infamous ^Z problem
- From: Old Wolf
- The infamous ^Z problem
- Prev by Date: Re: The infamous ^Z problem
- Next by Date: Re: The infamous ^Z problem
- Previous by thread: Re: The infamous ^Z problem
- Next by thread: Re: The infamous ^Z problem
- Index(es):
Relevant Pages
|