From eaf2e7950191474d22c4527b307fcf47988283c4 Mon Sep 17 00:00:00 2001 From: Sorina Pop Date: Thu, 22 Sep 2016 10:17:40 +0200 Subject: [PATCH] my fisrt commit --- Makefile | 5 +++++ hello.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Makefile create mode 100644 hello.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ff12ab --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +hello: hello.o + gcc -o hello hello.o + +hello.o: hello.c + gcc -c hello.c diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..870d77b --- /dev/null +++ b/hello.c @@ -0,0 +1,27 @@ +#include +#include + +int main(int argc, char *argv[]) { + + /* This is a comment in C */ + + printf("This is a C program\n"); + FILE *f = fopen("hello.txt", "w"); + if (f == NULL){ + printf("Error opening file!\n"); + exit(1); + } + + if (argc>1) { + printf("Hello %s !\n", argv[1]); + fprintf(f, "Hello %s !\n", argv[1]); + }else{ + printf("Hello world !\n"); + fprintf(f, "Hello world !\n"); + } + + /* print some text */ + fclose(f); + printf("This is the end of my C program\n"); + +} -- 2.47.1