Skip to content

Instantly share code, notes, and snippets.

@DiegoAscanio
Created September 5, 2016 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoAscanio/428448f6092851b4a9186cdeafcd97a3 to your computer and use it in GitHub Desktop.
Save DiegoAscanio/428448f6092851b4a9186cdeafcd97a3 to your computer and use it in GitHub Desktop.
/* 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