Question

Here is some code I could not get to format properly in markdown, this is straight C code, pasted into the text box with the '4 spaces' format to denote code:

#define PRINT(x, format, ...) \
if ( x ) { \
    if ( debug_fd != NULL ) { \
        fprintf(debug_fd, format, ##__VA_ARGS__); \
    } \
    else { \
        fprintf(stdout, format, ##__VA_ARGS__); \
    } \
}

It seems as though the '\' causes the newlines to be ignored. Ok fine, I am used to this in bash, but if I put '\' the second one doesn't show up. As if the second one is absorbed. Am I missing something?

Was it helpful?

Solution

You can also use the HTML tags <pre><code> in succession. I find this easier for pasting code into the window.

#define PRINT(x, format, ...)
if ( x ) 
{
    if ( debug_fd != NULL ) 
    { 
        fprintf(debug_fd, format, ##VA_ARGS); 
    } 
    else 
    { 
        fprintf(stdout, format, ##VA_ARGS); 
    } 
}

OTHER TIPS

Add at least four spaces or a hard tab before each line of the code. Like this:

#define PRINT(x, format, ...) \
if ( x ) { \
    if ( debug_fd != NULL ) { \
        fprintf(debug_fd, format, ##VA_ARGS); \
} \
else { \
    fprintf(stdout, format, ##VA_ARGS); \
} \
}
#define PRINT(x, format, ...)
if ( x ) 
{
    if ( debug_fd != NULL ) 
    { 
        fprintf(debug_fd, format, ##VA_ARGS); 
    } 
    else 
    { 
        fprintf(stdout, format, ##VA_ARGS); 
    } 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top