Hello world/Newline omission: Difference between revisions

From Rosetta Code
Content added Content deleted
({{header|C}})
Line 13: Line 13:
<lang basic>10 REM The trailing semicolon prevents a newline
<lang basic>10 REM The trailing semicolon prevents a newline
20 PRINT "Goodbye World!";</lang>
20 PRINT "Goodbye World!";</lang>

=={{header|C}}==

<lang c>#include <stdio.h>
int main(int argc, char *argv[]) {
(void) printf("Goodbye, World!"); /* We don't get newlines unless we embed them */
return EXIT_SUCCESS;
}</lang>


=={{header|Perl}}==
=={{header|Perl}}==

Revision as of 01:39, 25 July 2011

Hello world/Newline omission is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Some languages automatically insert a newline after outputting a string, unless measures are taken to prevent its output. The purpose of this task is to output the string "Goodbye, World!" to the terminal, preventing a trailing newline from occuring.

See also

BASIC

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>

C

<lang c>#include <stdio.h>

int main(int argc, char *argv[]) {

 (void) printf("Goodbye, World!");    /* We don't get newlines unless we embed them */
 return EXIT_SUCCESS;

}</lang>

Perl

<lang perl>print "Goodbye World!"; # A newline does not occur automatically</lang>

UNIX Shell

The behaviour of echo command is inconsistent across implementations. The -n parameter is not guaranteed to prevent a newline from occuring, so use a printf instead:

<lang sh>echo -n "Goodbye World!" # This may not work printf "Goodbye World!" # This works. newline is not automatically produced</lang>

ZX Spectrum Basic

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>