C: How to write to multiline macro in C?
How to write to multiline macro in C?
To write a multiline macro we have to use C's line splitting character, the '\'.
Here is a macro definition of LINE and the program which uses it:
#define LINE for ( i = 0 ; i < 80 ; i++ )\
printf ( "_" ) ;\
printf ( "\n" ) ;
main( )
{
int i ;
LINE ;
printf ( "S.No Roll No. Name Phy Math Chem\n" ) ;
LINE ;
}The macro LINE draws a horizontal line on the screen. The above program attempts to print the name of the fields of the students record in between the two lines. In the LINE macro we have used i as a variable hence, it has to be declared before we use the macro. Since we are using the macro in main( ) function, we have declared i before using the macro.




Comments
Log in or create a user account to comment.