question: regarding gdb

hello programmers,
i am new to programming, and i have this problem regarding using the (gdb).
so i have this code which is completely correct:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream> 
using namespace std; 

 bool is_equal(char *str1, char *str2){ 
 int i;
   for( i=0; str1[i]!='\0' && str2[i]!='\0'; i++)    
      if(str1[i]!=str2[i])    
         return false;   
  
  if(str1[i]!='\0' || str2[i]!='\0')   
      return false;

   return true;
}

int main(int argc, char *argv[]) { 
   if(argc >= 3)    
      cout << is_equal(argv[1], argv[2]) << endl;  

   return 0;
} 

new code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream> 
using namespace std; 

 bool is_equal(char **str1, char **str2){ // i have added (*) on each parameter
 int i;
   for( i=0; str1[i]!='\0' && str2[i]!='\0'; i++)    
      if(str1[i]!=str2[i])    
         return false;   
  
  if(str1[i]!='\0' || str2[i]!='\0')   
      return false;

   return true;
}

int main(int argc, char *argv[]) { 
   if(argc >= 3)    
      cout << is_equal(&argv[1], &argv[2]) << endl; // i have added (&) on both argvs. 

   return 0;
} 

so when i try to use the gdb to find out the values of str1 and str2 it gives me a message saying that " No symbol "str1" in current context. "
and when i try to use my breakpoint on the function it gives me " rogram exited normally."

i know that the question may seem dumb, but can you please guide me?
¿can you post your session? I mean how you run gdb, what parameters you pass it, the commands that you execute and the output for each command.
Also, how you are building your code.

> No symbol "str1" in current context.
That may mean that you are not in the `is_equal()' function, so there is no `str1' variable, or that you didn't compile with debug information (-ggdb flag)

> when i try to use my breakpoint on the function it gives me "Program exited normally."
¿did you provide the arguments to the program?
Try to put the breakpoin in `main()' and step from there.
Topic archived. No new replies allowed.