fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <linux/limits.h>
  4. #include <unistd.h>
  5.  
  6. char * current_dir()
  7. {
  8. char *s = malloc(PATH_MAX * sizeof (*s));
  9. getcwd(s, PATH_MAX);
  10. return s;
  11. }
  12.  
  13. int main(int argc, char **argv)
  14. {
  15. char *s;
  16. if (argc > 1)
  17. s = *(argv + 1);
  18. else
  19. s = current_dir();
  20.  
  21. printf("%s\n", s);
  22. // problem here, don't know if memory should be freed
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
/home/DSUOCz