Re: Carriage Returns

From: Johan Aurér (aurer_at_axis.com)
Date: 10/09/03


Date: Thu, 9 Oct 2003 13:39:33 +0200

On Thu, 9 Oct 2003, Joona I Palaste wrote:

> Nimmy <nojunk@please.com> scribbled the following:
> > Hi,
>
> > I have a data file and I want to remove Carriage returns. Any one has any C
> > code/program which does this? I am working on Windows XP machine.....I don't
> > have access to UNIX machine. But I need to send this data file to the Unix
> > machine once I remove the carriage retunrns from my XP machine.
>
> Here's a simple filter-type program.
>
> #include <stdio.h>
> int main(void) {
> int cr = '\r'; /* the code for carriage return */
> int c;
> while ((c = getchar()) != EOF) {
> if (c != cr) {
> putchar(c);
> }
> }
> return 0;
> }
>
> Simply redirect stdin from the file you want to remove carriage
> returns from and redirect stdout to the new file.

No, both stdin and stdout are text streams by default. A one-to-one
correspondence between the characters of a text stream and the
external representation is not mandated by the standard. You need to
use binary streams.

-- 
aurer@axis.com


Relevant Pages

  • Re: Carriage Returns
    ... But I need to send this data file to the Unix ... >> machine once I remove the carriage retunrns from my XP machine. ... opposite operation is not going to happen, because the output file is ...
    (comp.lang.c)
  • Carriage Returns
    ... I have a data file and I want to remove Carriage returns. ... I am working on Windows XP machine.....I don't ... have access to UNIX machine. ...
    (comp.lang.c)
  • Re: Carriage Returns
    ... > I have a data file and I want to remove Carriage returns. ... > C code/program which does this? ... > the Unix machine once I remove the carriage retunrns from my XP machine. ...
    (comp.lang.c)