Re: Macro inside a string
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 10:48:16 -0400
Sweta wrote:
Hi,
I have the following code -
#include <stdio.h>
#define VAR i
main()
{
int VAR;
VAR = 10;
printf("VAR = %d", VAR);
}
As of now, this code prints VAR = 10
I want to have the output as i = 10 i.e. the macro replacement should
be printed as string. Does anybody have any idea how we can do it? Do
we have something like #, ## for macros which do not have argument
list.
#define STRING(x) STRING2(x)
#define STRING2(x) # x
....
printf (STRING(VAR) " = %d\n", VAR);
/* or */
printf ("%s = %d\n", STRING(VAR), VAR);
See also Question 11.17 in the comp.lang.c FAQ
at <http://www.c-faq.com/>.
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- References:
- Macro inside a string
- From: Sweta
- Macro inside a string
- Prev by Date: Macro inside a string
- Next by Date: Re: Problem with fscanf()....
- Previous by thread: Macro inside a string
- Index(es):
Relevant Pages
|