Mail Archives: djgpp/2001/11/09/04:04:29
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 -