diff --git a/hello.c b/hello.c new file mode 100644 index 0000000000000000000000000000000000000000..12121ff1e9c4e38ee58144683945245fabe5a65d --- /dev/null +++ b/hello.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int main() { + puts("Hello World"); + printf("The answer is %d\n",42); + putchar('\n'); + fprintf(stdout,"Yes\n"); + + write(1,"Yes!",strlen("Yes!")); + return 42; +} diff --git a/helloworld.c b/helloworld.c new file mode 100644 index 0000000000000000000000000000000000000000..fd513b57a0eba1e7d1b1a91bead5e73c1752a555 --- /dev/null +++ b/helloworld.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int main() { + puts("Hello World"); // puts "put string" also prints a newline + + printf("The answer is %d\n",42); // "print formatted" + + putchar('\n'); // Print a single character + + fprintf(stdout,"Yes\n"); // print to a file - in this case standard out + + // All of the above are well known C standard library functions + // Under the covers, the actual writing requires a system call. + // Linux supports the POSIX API. All of the above ultimately call write: + + // The system call to send 5 bytes to file descriptor #1 (standout output) + write(1, "POSIX", 5 ); + write(1, " ROCKS", strlen(" ROCKS")); + return 42; +}