I suggest you use Quzah's suggestion for debugging. printf() is a lot easier to use than GDB.
This is a discussion on What was wrong with this code?? within the C Programming forums, part of the General Programming Boards category; I suggest you use Quzah's suggestion for debugging. printf() is a lot easier to use than GDB....
I suggest you use Quzah's suggestion for debugging. printf() is a lot easier to use than GDB.
Here is an example that might be a little more pertinant to you:
The above code will probably give you a seg fault. If you add in a printf() statement like so:Code:int a, c, b = 10; char array[10]; for(a = 0; a <= b; a++) { c = array[a]; }
You will (hopefully) get the seg fault before it prints "About to access index 10". This helps you to realize that you are accessing the array outside its bounds.Code:int a, c, b = 10; char array[10]; for(a = 0; a <= b; a++) { printf("About to access index %d\n",a); c = array[a]; }
Using quzah's example you're guaranteed that the debugging message will be shown because of the fflush() call.
If you understand what you're doing, you're not learning anything.