Created
September 5, 2016 13:00
-
-
Save DiegoAscanio/428448f6092851b4a9186cdeafcd97a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* printmsg.c: print a message on the console */ | |
/* printmsg.c: print a message on the console */ | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
char *message; | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s <message>\n", | |
argv[0]); | |
exit(1); | |
} | |
message = argv[1]; | |
if (!printmessage(message)) { | |
fprintf(stderr,"%s: couldn't print your message\n",argv[0]); | |
exit(1); | |
} | |
printf("Message Delivered!\n"); | |
exit(0); | |
} | |
int printmessage(char *msg) { | |
FILE *f; | |
f = fopen("/dev/stdout", "w"); | |
if (f == (FILE *)NULL) { | |
return 0; | |
} | |
fprintf(f, "%s\n", msg); | |
fclose(f); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment