1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char **argv) { char buf[1024]; if(!getcwd(buf, sizeof(buf))) { perror("Error getting current directory"); return EXIT_FAILURE; } puts(buf); return 0; }