create_file.cxx 541 B

12345678910111213141516171819202122232425262728
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main (int argc, char *argv[])
  4. {
  5. if (argc < 2)
  6. {
  7. fprintf(stderr, "Missing name of file to create.\n");
  8. return EXIT_FAILURE;
  9. }
  10. FILE *stream = fopen(argv[1], "w");
  11. if(stream == NULL)
  12. {
  13. fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
  14. return EXIT_FAILURE;
  15. }
  16. if(fclose(stream))
  17. {
  18. fprintf(stderr, "Unable to close %s!\n", argv[1]);
  19. return EXIT_FAILURE;
  20. }
  21. fprintf(stdout, "Creating %s!\n", argv[1]);
  22. return EXIT_SUCCESS;
  23. }