tags:

views:

107

answers:

4
#include<stdio.h>
int main(int argc, char **argv)
{
 int a,b,c;

 printf("enter two numbers:-");
 if( scanf("%d \t %d",&a,&b)  == 2 )
 {
    c=a+b;
     printf("addition of numbers= %d",c);
 }
 else {
        printf("please enter a valid input");
        getchar();
    }
}

how to debug this code line by line in the c-debugger? please , help me...... i m using linux platform.

+3  A: 

Which debugger? In MS Visual Studio Express just place a breakpoint at the first line of the code and then start "Debug".

On a Linux platform, compile the code with debugging flags (-g) and then run the resulting executable under gdb.

Suppose your file is test.c. Compile:

gcc -g -o test test.c

Then debug:

gdb test

See this article for more details. Google "linux debug c program" for even more.

Eli Bendersky
i m using linux;thankyou for the information.
Cold-Blooded
@Mahya: then I've updated the answer with some more information
Eli Bendersky
thank you so much,now i got it.
Cold-Blooded
A: 

There's no such thing a "the C debugger". A debugger is a tool that a compiler manufacturer may (or may not) create for use with their particular compiler. There are hundreds of different ones.

In general, what'd you do with any debugger if you don't know where to start would be to set a breakpoint at the first line, and single-step through your program, examining variables and whatnot as you go.

T.E.D.
+1  A: 

Theres gdb a command line debugger.

Theres ddd a graphical debugger.

Nandish
A: 

jus read man gdb. Its a gr8 man page helps in debugging for linux platform.

Nandish