Re: stdin ? stdin ? What's wrong with stdin? -- an UPDATE
From: Norm Dresner (ndrez_at_att.net)
Date: 02/17/05
- Next message: Joe: "ATL: creating object fails"
- Previous message: Tom Widmer: "Re: how to quickly initilize a struct component?"
- In reply to: Norm Dresner: "Re: stdin ? stdin ? What's wrong with stdin?"
- Next in thread: Tom Widmer: "Re: stdin ? stdin ? What's wrong with stdin? -- an UPDATE"
- Reply: Tom Widmer: "Re: stdin ? stdin ? What's wrong with stdin? -- an UPDATE"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Feb 2005 10:41:59 GMT
The project is a C++ Win32 Console App in VC++6. There are 12 .cpp-files
and 3 .h-files with ~3300 lines of code so I can't possibly present
everything here. As the program is starting up, it checks the command-line
for files to process which, for each of them, means reading the file,
producing an intermediate file which is closed and reopened for reading, and
this is read and the "output" file written. During my initialization, the
program checks to see if an output file exists for an input file and, if the
user hasn't already requested automatic deletion of pre-existing files, asks
the user if it's okay to delete an output file. The code snippet in that
module is
> > > if( DoesFileExist( FullOutputFileName ) )
> > > {
> > > if( !AutoDeleteOuputFiles )
> > > {
> > > printf( "-------- Output file exists? Delete it or skip
input file ([s]/d)? " );
> > > fgets( aux , sizeof( aux ) - 1 , stdin );
> > > }
> > > else
> > > ...
and everyone agrees that there's nothing wrong with the code as written, but
the program crashes with an access violation on the fgets() line. aux is
declared as char[1025] a few lines above and right-clicking in the debugger
just before the fgets() call is executed confirms this.
NEW INFORMATION: If I replace fgets( aux ... ) with gets( aux ) the program
runs perfectly!!!!! This means, at least to me, that there's really nothing
wrong with the "code" or with the "stdin" input stream because that's what
gets() uses. ALSO ... I started a brand-new console-app project which
contains just the following code:
#include <libc.h /* this is my own */
/* include-just-about */
/* -everything-I'll-need */
/* header file that's also */
/* included in the */
/* previous program too */
int main(int argc, char* argv[])
{
char aux[1025];
printf("What's up doc? ");
fgets( aux , sizeof( aux ) - 1 , stdin );
printf( "\n\nYou entered \"%s\"\n" , aux );
return 0;
}
and this works just fine. SO ... There's obviously something in the way the
first program is setup -- a library or something -- that causes it to crash.
This is the only place in the program that stdin is used or any input from
the console is required. What should I be looking for? Could I possibly
be trashing some pointer somewhere? I don't quite see how if gets()
works because it looks like it calls getchar() which does fgetc() from
stdin itself.
Since I'm likely to be the only one using this program -- although a trusted
co-worker with equally high and obscure security clearance might be too
eventually -- should I just shrug my shoulders and leave the gets() call in
place or am I just deferring the problem until later?
Thanks
Norm
- Next message: Joe: "ATL: creating object fails"
- Previous message: Tom Widmer: "Re: how to quickly initilize a struct component?"
- In reply to: Norm Dresner: "Re: stdin ? stdin ? What's wrong with stdin?"
- Next in thread: Tom Widmer: "Re: stdin ? stdin ? What's wrong with stdin? -- an UPDATE"
- Reply: Tom Widmer: "Re: stdin ? stdin ? What's wrong with stdin? -- an UPDATE"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|