formatting long strings using sprintf() without including tabs or newlines 
Author Message
 formatting long strings using sprintf() without including tabs or newlines

Hello,

I have the following problem:

if I have a very long string to be formatted, and I want to use sprintf(),  
I can use case 3 below.  However, it doesn't look good on the printed code  
or on the editor's screen.  Case 1 is the prefered one in this regard, but  
from the output (listed below) it doesn't accomplish the task.  Case 2  
accomplishes the task partially: there is a tab on my output".

This question is about C code visual organization...

Any insights on how to "beautify" the code, yet, have the entire string  
sprintf'ed without tab or newline chars?

/*
test.c - testing long printf statements...
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
        /* case 1 - this looks visually well organized on my screen editor  
*/
        printf("hello, my name is such and such ",
                        "and here are my credentials" ,
                        "\n");
        printf("\n");

        /* case 2 - line splicing - A12.2 of K&R p 229 */
        printf("hello, my name is such and such \
        as this and this\n");

        /* case 3 - this looks visually unorganized on my screen editor */
        printf("hello, my name is such and such as here are my  
credentials:  first of all, this is a very long line, and it will wrap  
around my screen editor.  \n");

        return 1;

Quote:
}

/* output:

hello, my name is such and such
hello, my name is such and such         as this and this
hello, my name is such and such as here are my credentials:  first of all,  
this is a very long line, and it will wrap around my screen editor.  

*/



Tue, 03 Oct 1995 00:01:53 GMT  
 formatting long strings using sprintf() without including tabs or newlines

If you have an ANSI compiler you ought to be able to use the string
literal concatenation feature ala:

        printf( "%s\n",

        "This is the first line "
        "and this is the second, "
        "but it will all be concatenated together."

        );

--
Gary H. Merrill  [Principal Systems Developer, C Compiler Development]
SAS Institute Inc. / SAS Campus Dr. / Cary, NC  27513 / (919) 677-8000



Tue, 03 Oct 1995 03:38:07 GMT  
 formatting long strings using sprintf() without including tabs or newlines

|>
|> if I have a very long string to be formatted, and I want to use sprintf(),  
|> I can use case 3 below.  However, it doesn't look good on the printed code  
|> or on the editor's screen.  Case 1 is the prefered one in this regard, but  
|> from the output (listed below) it doesn't accomplish the task.  Case 2  
|> accomplishes the task partially: there is a tab on my output".
|>
|> This question is about C code visual organization...
|>
|> Any insights on how to "beautify" the code, yet, have the entire string  
|> sprintf'ed without tab or newline chars?
|>

Try this out ...

        printf("hello, my name is such and such "
                "and here are my credentials: "
                "first of all, "
                "this is a very long line, "
                "but I've fixed it so that "
                "it looks just great on my "
                "lousy old rusty screen editor. "
                "This is string concatenation, which "
                "I am almost sure is ANSI C.\n" );

-Avijit-

--
+--------------+------------------------------+--------------------------+



+--------------+------------------------------+--------------------------+



Wed, 04 Oct 1995 02:48:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. formatting long strings using sprintf()

2. Need function to convert float/double/long to string using a specified format

3. format string for long long

4. insert newlines into long string

5. How to format diskette without using format.com ?

6. number to string without sprintf ?

7. short/long/long long Formatting questions

8. Writing to CString using sprintf format

9. format string with tab \t

10. convert string to long, and long to string

11. Printing formatted string to file without \0

12. format specifier for unsigned long long

 

 
Powered by phpBB® Forum Software