printing a block of text

E

Ed

Hi,

Could you tell me what the equivalent of this perl code would be in C
please?

print EOT<<
I want
to print over
multiple lines in c
without doing lots of printfs
EOT

Thanks!

Ed.
 
B

Ben Pfaff

Ed said:
Could you tell me what the equivalent of this perl code would be in C
please?

print EOT<<
I want
to print over
multiple lines in c
without doing lots of printfs
EOT

fputs ("I want\n"
"to print over\n"
"multiple lines in c\n"
"without doing lots of printfs\n",
stdout);
 
W

Walter Roberson

Ed said:
Could you tell me what the equivalent of this perl code would be in C
please?
print EOT<<
I want
to print over
multiple lines in c
without doing lots of printfs
EOT

#include <stdio.h>
int main(void) {
puts( "I want\nto print over\nmultiple lines in c\nwithout doing lots of printfs" );
return 0;
}

(Note: puts() automatically supplies the final \n )
 
K

Kevin D. Quitt

#include <stdio.h>
int main(void) {
puts( "I want\nto print over\nmultiple lines in c\nwithout doing lots of printfs" );
return 0;

Or:

puts(
"I want\n"
"to print over\n"
"multiple lines in c\n"
"without doing lots of printfs\n"
);
 
E

Ed

Walter said:
#include <stdio.h>
int main(void) {
puts( "I want\nto print over\nmultiple lines in c\nwithout doing lots of printfs" );
return 0;
}

(Note: puts() automatically supplies the final \n )

Thanks for that. Is there a way I can do it without having to specify
the \n's though?
I'm trying to print out an HTML page, so it'd make life easier if I
could do it in the Perl style above.
 
W

Walter Roberson

Ed said:
Thanks for that. Is there a way I can do it without having to specify
the \n's though?
I'm trying to print out an HTML page, so it'd make life easier if I
could do it in the Perl style above.

In short, NO: the alternatives are more complex and uglier.
 
E

Eric Sosman

Ed wrote On 09/06/06 17:52,:
Walter Roberson wrote:




Thanks for that. Is there a way I can do it without having to specify
the \n's though?
I'm trying to print out an HTML page, so it'd make life easier if I
could do it in the Perl style above.

const char *text[] = {
"I want",
"to print over",
"multiple lines in c",
"without doing lots of printfs",
};
int i;
for (i = 0; i < sizeof text / sizeof text[0]; ++i)
puts(text);

.... but it seems to me the embedded \n's are more convenient.
What's your problem with them?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top