From 80467d446861240117422e5429e8c2eb305a376d Mon Sep 17 00:00:00 2001 From: angrave <angrave@illinois.edu> Date: Thu, 6 Aug 2015 14:11:59 -0500 Subject: [PATCH] helloworld.c --- hello.c | 13 +++++++++++++ helloworld.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 hello.c create mode 100644 helloworld.c diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..12121ff --- /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 0000000..fd513b5 --- /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; +} -- GitLab