Re: The infamous ^Z problem
- From: "Joachim Schmitz" <nospam.jojo@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 May 2007 08:55:44 +0200
"Eigenvector" <m44_master@xxxxxxxxx> schrieb im Newsbeitrag
news:XOydnUSznrdFKc7bnZ2dnUVZ_jWdnZ2d@xxxxxxxxxxxxxx
^Z typically is used for Job-Control, in Shells that support it, to suspend
"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.
the forground job, so the shell would consum it before your program gets a
chance... check the output of 'stty -a'
This is of course OT here and also I might be utterly wrong...
Bye, Jojo
.
- Follow-Ups:
- Re: The infamous ^Z problem
- From: Keith Thompson
- Re: The infamous ^Z problem
- References:
- The infamous ^Z problem
- From: Eigenvector
- Re: The infamous ^Z problem
- From: Old Wolf
- Re: The infamous ^Z problem
- From: Eigenvector
- The infamous ^Z problem
- Prev by Date: pointers and beginnings of arrays
- Next by Date: Re: pointers and beginnings of arrays
- Previous by thread: Re: The infamous ^Z problem
- Next by thread: Re: The infamous ^Z problem
- Index(es):
Relevant Pages
|