mardi 29 décembre 2020

How to track a flow of a c program?

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...

Aucun commentaire:

Enregistrer un commentaire