]> Creatis software - demoSorina.git/blob - hello.c
Added a second argument for the file name
[demoSorina.git] / hello.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char *argv[]) {
5         if (argc == 3) {
6                 /*Opening the file provided as a second argument*/
7                 FILE *f = fopen(argv[2], "w");
8                 if (f == NULL){
9                   printf("Error opening file!\n");
10                   exit(1);
11                 }
12                 /*Saying hello to the name provided as a first argument*/
13                 printf("Hello %s !\n", argv[1]);
14                 fprintf(f, "Hello %s !\n",  argv[1]);
15                 fclose(f);
16         }else{
17                 printf("This is a C program expecting 2 arguments: the name to say hello to and the output file name\n");
18                 printf("You have not provided the correct number of arguments\n");
19                 exit(1);
20         }
21         exit(0);
22
23 }
24