Have you had a look at getcwd()
?
#include <unistd.h> char *getcwd(char *buf, size_t size);
Simple example:
#include <unistd.h> #include <stdio.h> #include <limits.h> int main() { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) != NULL) { printf("Current working dir: %s\n", cwd); } else { perror("getcwd() error"); return 1; } return 0; }
Related Posts:
- What does it mean to write to stdout in C?
- wait(null) and wait(&status) C language and Status
- What do the dup() and dup2() systems really do?
- Reasoning behind C sockets sockaddr and sockaddr_storage
- How to pretty print XML from the command line?
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What are file descriptors, explained in simple terms?
- How to kill a process running on particular port in Linux?
- Display exact matches only with grep
- What are .a and .so files?
- Connect: Socket operation on non-socket
- Connect: Socket operation on non-socket
- How to split a delimited string into an array in awk?
- What is the difference between read and pread in unix?
- Display exact matches only with grep
- What does ^M character mean in Vim?
- What is a bus error? Is it different from a segmentation fault?
- What does WEXITSTATUS(status) return?
- What do ‘real’, ‘user’ and ‘sys’ mean in the output of time(1)?
- mkdir’s “-p” option
- Shell script “for” loop syntax
- What is a bus error? Is it different from a segmentation fault?
- What can cause a “Resource temporarily unavailable” on sock send() command
- When could or should I use chmod g+s on a file or directory?
- How to Sum a column in AWK?
- Equivalent of *Nix ‘which’ command in PowerShell?
- What is the difference between SIGSTOP and SIGTSTP?
- How to colorize diff on the command line
- How to colorize diff on the command line
- How to read a file into a variable in shell?
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- Is there any simple way to benchmark Python script?
- gpg decryption fails with no secret key error
- What is the difference between tar and zip?
- Display current path in terminal only
- Which of sprintf/snprintf is more secure?
- C fopen vs open
- What is `S_ISREG()`, and what does it do?
- Reaching EOF with fgets
- What generates the “text file busy” message in Unix?
- How can I send an email through the UNIX mailx command?
- Rename multiple files based on pattern in Unix
- What is the difference between a symbolic link and a hard link?
- SCP Permission denied (publickey). on EC2 only when using -r flag on directories
- binary operator expected error when checking if a file with full pathname exists
- What is special about /dev/tty?
- How do I do ‘mount –bind’ in /etc/fstab?
- How to read backward from the end of file in less or more?
- Getting the last match in a file using grep
- How big can a 64 bit unsigned integer be?
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- Implementing Taylor Series for sine and cosine in C
- Working on code to calculate cosine with factorial sum
- How to use execvp()
- How to use execvp() to execute a command
- How does strtok() split the string into tokens in C?
- warning: implicit declaration of function
- warning: implicit declaration of function
- What is *(uint32_t*)?
- What does (~0L) mean?
- pthread_join() and pthread_exit()
- How do I pause my shell script for a second before continuing?
- What is size_t in C?
- What is the difference between float and double?
- what is Segmentation fault (core dumped)? [duplicate]
- What causes a segmentation fault (core dump) to occur in C?
- uint8_t vs unsigned char
- How to use symbols of extended ASCII table in C?
- Two questions about basic C programs
- What is the difference between ++i and i++?
- Using boolean values in C
- What does “collect2: error: ld returned 1 exit status” mean?
- How to convert an int to string in C?
- typedef struct vs struct definitions [duplicate]
- How to print in C
- What is the effect of extern “C” in C++?
- Why should we typedef a struct so often in C?
- Why are #ifndef and #define used in C++ header files?
- Arrow operator (->) usage in C
- strdup() – what does it do in C?
- strdup() – what does it do in C?
- What is a string of hexadecimal digits?
- Why should we typedef a struct so often in C?
- What exactly is the difference between “pass by reference” in C and in C++?
- What is the difference between ++i and i++?
- What can be the reasons of connection refused errors?
- What does “collect2: error: ld returned 1 exit status” mean?
- How to convert an int to string in C?
- typedef struct vs struct definitions [duplicate]
- When to use extern “C” in simple words? [duplicate]
- Floating point exception( core dump
- sudo: npm: command not found
- In the shell, what does ” 2>&1 ” mean?
- What does the question mark character (‘?’) mean?
- Cannot figure out how to use getchar(); in C
- Floating point exception (core dumped)
- Undefined reference to pthread_create in Linux