Re: [Dev-C++] about debugging a C program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <gi...@li...> - 2002-02-12 17:41:23
|
Hello Javier,
I've tried the code that you posted with both the CLI version of gdb (I
mean the one you get together with Dev-C++) and the GUI version (the one
you used). I had no problem, the program worked as expected. So I can't
tell you what is wrong.
There are a few things about your code, though, which I do not understand.
1. I see that you are worried about casting the value returned by some
functions (like "fprintf" or "fclose") to "void", even if you assign the
return value to no variable.
2. The function "ckopen" is not supposed to modify the value of "name", but
you use a "char*" instead of a "const char*". This also applies to the
other argument and to the function "fatalf".
When I compiled your code the gcc compiler complained (i.e. issued a
warning message) that "b.txt" is a "const char*" and you are passing it to
a function ("ckopen") that expects a "char*".
3. You test for the ASCII character 0.
4. You test for the ASCII character 32 instead of the character literal ' '.
I have rearranged your code and am sending you the result, in the hope that
it helps.
At 14:32 11/02/02 -0600, Javier Martinez wrote:
>...
> > I would like to help solving your problem, but I
> > need a little more
> > informations:
> > (1) which debugger are you using: the command line
> > "gdb" or the GUI cygwin
> > version of gdb?
>
>I'm using the GUI cygwin the insight program for
>win32.
>
> > (2) Couild you post a small program where the
> > behavior you experienced occurs?
>
>sure I have a complete small program that presents
>also the bad behavior...
>
> > I need a bit more code to understand the way you set
> > the value of the
> > variable "name".
>
>BEGIN---------------------------
>#include <stdio.h>
>#include <stdlib.h>
>
>
>int fatalf(char *msg, char *val)
>{
> (void) fprintf(stderr, msg, val);
> (void) putc('\n', stderr);
> exit(1);
>}
>
>FILE *ckopen(char *name, char *mode)
>{
> FILE *fp;
>
> if ((fp = fopen(name, mode)) == NULL)
> fatalf("Cannot open %s.", name);
> return(fp);
>}
>
>
>int main(int argc, char *argv[])
>{
> FILE *Ap;
> int M,symbol;
>
> Ap = ckopen("b.txt", "r");
> for (M = 0; ( symbol = getc(Ap)) != EOF ; )
> if ( symbol != '\n' && (symbol != 32) && (symbol
>!= 0))
> ++M;
> (void) fclose(Ap);
>
> printf("%d",M);
> return 0;
>}
>
>END-----------------------------
>
>Notes:
>1* This program just take a text file and counts the
>number of characters in it...
>
>2* b.txt is a text file that really exist.. and when I
>run the program it works...
>
>3* but if I try to debug the program the debugger
>fails to open it. when reads the fopen instruction
>doesn't get a address for the text file to be open,
>just returns NULL...
>
>
>Javier
>
> > --
> > gisan
--
gisan
gi...@li... |