I'ts more of a general question: how to handle the execution path of a c program, which consist of multiple functions? For example, i have a following c program:
void test_if_statement(int num)
{
if (num > 0)
//do smth
;
else
//do smth else
;
}
int main(void)
{
int num;
printf("enter an int value:");
scanf("%d", &num);
test_if_statement(num);
return 0;
}
Currently i'm using something like this to see where did my function go in if statements:
void test_if_statement(int num)
{
if (num > 0)
printf("i'm here\n");
//do smth
else
printf("now i'm there\n");
//do smth else
}
How can I keep it simple and more universal?;) Putting printf in every if-else pair seems unreasonably bulky...
There is nothing wrong using
printfstatements to track or log program flow for the purpose of learning, or testing during development. But a good debugger will probably serve the purpose just as well without having to add in-line code.Depending on your environment there is a large list of debugger options available.
Following is an overview of debugging programs:
Key things that you can use the debugger to determine are:
Much more detail here