954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

code executed

I'd like to write C++ program that will count the number of times each line of the code get executed

can any one help me

thanks in advance

farag
Junior Poster in Training
61 posts since Feb 2008
Reputation Points: 7
Solved Threads: 2
 

I suppose if you have a program that contains 1,000 lines you should have an int array of 1,000 ints and do something like this

int counters[1000] = {0};

int main()
{
    counters[__LINE__]++;
    cout << "Hello World\n";
    counters[__LINE__]++;
    return 0;
};


__LINE__ is a macro that returns the current line number of the program. I'm not certain if that macro is available on all compilers or not.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You