Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

In C++, I need a macro that builds a string that includes the file and the line number..

C++, Linux

as part of my effort to understand an application I have, I need to build a macro that automatically builds a string with the file number and the line number.
I can print that string that will show me the execution path.
I am going to add this Macro in places and print the output!
0
EmadGirgis
Asked:
EmadGirgis
  • 2
1 Solution
 
sunnycoderCommented:
__LINE__, __FUNCTION__, __FILE__

#define LOG_HERE printf("%s %s %d\n",__FILE__,__FUNCTION__,__LINE__)
0
 
EmadGirgisAuthor Commented:
Thank you very much...
I need to advance this so it would generate me a string to pass to other function!!

So I mean
string S
S would be equal to
("%s %s %d\n",__FILE__,__FUNCTION__,__LINE__)
0
 
sunnycoderCommented:
The format specifiers work only with printf family of functions ... to for a string, use sprintf

sprintf (mystring, "%s %s %d\n",__FILE__,__FUNCTION__,__LINE__);

Note ... snprintf is safer than printf .. make sure mystring has sufficient memory
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now