delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/11/09/04:04:29

Message-ID: <000701c168fc$bbe244e0$3bf092c3@cedric>
From: =?iso-8859-1?Q?C=E9dric_Lucantis?= <c DOT lucantis AT popup-interactive DOT com>
To: <djgpp AT delorie DOT com>
References: <MPG DOT 165491792e225e13989690 AT netnews DOT worldnet DOT att DOT net>
Subject: Re: Can't Even Read File Correctly
Date: Fri, 9 Nov 2001 09:58:42 +0100
Organization: =?iso-8859-1?Q?POP'UP_Int=E9ractive?=
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Reply-To: djgpp AT delorie DOT com

You are reading chararacters (text) from the standart input. Why didn't you
open your file with "wt" instead of "wb" ? I remember I already had this
kind of problem and I think (hope) it can be the solution ...

----- Original Message -----
From: Robert Neinast <neinast AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
To: <djgpp AT delorie DOT com>
Sent: Thursday, November 08, 2001 6:56 PM
Subject: Can't Even Read File Correctly


>
> This is driving me nuts.  In C, I'm doing simple getchars from
> stdin and writing to a file, and it keeps getting truncated.
> Anybody have any ideas what the heck I'm doing wrong????
> (I have 15 years experience with C programming, so either I
> am doing something incredibly stupid, or something weird is
> going on.)  This is on Windows 98, djgpp 2.03.
>
> My file (nnn.c) is
>
> ===============================
> #include <stdio.h>
>
> main(argc, argv)
> int argc;
> char *argv[];
>
> {
> int c;
>
> FILE *fp;
>
> if ((fp = fopen("xx.aa", "wb"))==NULL)
> {
> fprintf(stderr, "could not open output file\n");
> exit(1);
> }
>
> while ((c=getchar())!=EOF)
> {
> putc(c, fp);
> }
>
> fclose(fp);
>
> exit(0);
> }
> ===============================
>
> $ ls -l
> -rw-r--r--   1 dosuser  root          296 Nov  8 12:40 nnn.c
> $ gcc -o nnn.exe nnn.c
> $ ls -l
> -rw-r--r--   1 dosuser  root          296 Nov  8 12:40 nnn.c
> -rwxr-xr-x   1 dosuser  root       111608 Nov  8 12:54 nnn.exe
> $ nnn < nnn.exe
> $ ls -l
> -rw-r--r--   1 dosuser  root          296 Nov  8 12:40 nnn.c
> -rwxr-xr-x   1 dosuser  root       111608 Nov  8 12:54 nnn.exe
> -rwxr-xr-x   1 dosuser  root          432 Nov  8 12:54 xx.aa
>
> So, why is it truncated so???
>
> Thanks in advance,
> Bob
> --
> . . . and shun the Frumious Bandersnatch
> Robert A. Neinast
> Pickerington, OH
>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019