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 do I pause my shell script for a second before continuing?
- What is the effect of extern “C” in C++?
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- In the shell, what does ” 2>&1 ” mean?
- Floating point exception (core dumped)
- Correct format specifier for double in printf
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- What is the difference between char s[] and char *s?
- How do I grep recursively?
- Error “initializer element is not constant” when trying to initialize variable with const
- warning: implicit declaration of function
- C dynamically growing array
- Argument list too long error for rm, cp, mv commands
- How to printf “unsigned long” in C?
- Difference between using “chmod a+x” and “chmod 755”
- Why do I get an assertion failure?
- Given two directory trees, how can I find out which files differ by content?
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- expression must have integral type
- OSError – Errno 13 Permission denied
- Why is %c used in C?
- Anyone know how to solve the error of “collect2.exe: error: ld returned 1 exit status” when a program in C is running?
- How to iterate over a string in C?
- Where is the C auto keyword used?
- How can one print a size_t variable portably using the printf family?
- Why are hexadecimal numbers prefixed with 0x?
- Uninitialized value was created by a heap allocation
- Makefile:1: *** missing separator. Stop
- Invalid type argument of unary ‘*’ (have ‘int’) Error in C
- Why do I get “cast from pointer to integer of different size” error?
- Excess elements of scalar initializer for pointer to array of ints
- How does one represent the empty char?
- Can I define a function inside a C structure?
- How to display hexadecimal numbers in C?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- Difference between char *argv[] and char **argv for the second argument to main()
- How do you format an unsigned long long int using printf?
- error : storage class specified for parameter
- Dereference void pointer
- Use of flag in c?
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory
- Level vs Edge Trigger Network Event Mechanisms
- How to convert integers to characters in C?
- variably modified array at file scope in C
- How to use random() in C [duplicate]