This brief description of how to use gdb will assume that you are tracing through the following program which has been saved as tri.c.
/* tri.c
DFStermole
28 September 98
Purpose: Calc the area of a triangle
*/
#include <stdio.h> /* standard I/O header file */
void main()
{
int b; /* base */
int h; /* height */
float A; /* Area */
/* -------------------Introduction------------------ */
printf("This program calculates the area of a triangle\n");
printf("after you enter its dimensions.\n");
printf("When asked to, type in a dimension and hit the ENTER key.\n");
printf("\n");
/* -------------------Inputting Data------------------*/
printf("What is the length of the triangle's base? ");
scanf("%d", &b);
printf("What is the triangle's height? ");
scanf("%d", &h);
/* -------------------Calculation------------------ */
A = b * h / 2.0;
/* -------------------Printing Results------------------ */
printf("\n");
printf("The area of a triangle with a base of %d units and\n", b);
printf("a height of %d units is %.1f square units.\n", h, A);
}
The .gdbinit file is automatically executed when gdb is run. Create a .gdbinit file with the following lines and then run gdb.
b 16 r