DIR Return Create A Forum - Home
---------------------------------------------------------
techsuns
HTML https://techsuns.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Puzzles && Algorithms
*****************************************************
#Post#: 364--------------------------------------------------
Can you write a small which prints character x for me
By: kranthipls Date: December 7, 2012, 2:39 am
---------------------------------------------------------
Write a C macro PRINT(x) which prints x???
Do not use a function call in a macro
#Post#: 370--------------------------------------------------
Re: Can you write a small which prints character x for me
By: satya Date: December 7, 2012, 2:55 am
---------------------------------------------------------
can we use putchar()??
#Post#: 371--------------------------------------------------
Re: Can you write a small which prints character x for me
By: kranthipls Date: December 7, 2012, 3:17 am
---------------------------------------------------------
Use Whatever you want?
#Post#: 372--------------------------------------------------
Re: Can you write a small which prints character x for me
By: ravusairam Date: December 7, 2012, 3:45 am
---------------------------------------------------------
#define PRINT(x) printf("%c",x);
#Post#: 373--------------------------------------------------
Re: Can you write a small which prints character x for me
By: kranthipls Date: December 7, 2012, 4:10 am
---------------------------------------------------------
Ravu You can execute it. It does not work.
Anyway I do not want any function call in the macro...........
#Post#: 404--------------------------------------------------
Re: Can you write a small which prints character x for me
By: kranthipls Date: December 10, 2012, 11:58 pm
---------------------------------------------------------
In C, there’s a # directive, also called ‘Stringizing
Operator’, which does this magic. Basically # directive converts
its argument in a string. So the program can be written as
follows:
#define PRINT(x) (#x)
int main()
{
printf("%s",PRINT(x));
return 0;
}
Now if the input is PRINT(x), it would print x. In fact, if the
input is PRINT(techsuns), it would print techsuns.
#Post#: 412--------------------------------------------------
Re: Can you write a small which prints character x for me
By: ravusairam Date: December 11, 2012, 8:47 am
---------------------------------------------------------
nice one!!
*****************************************************