Current dir in C
Hi,
Does anyone know how to get the current working directory within a C program? Kind regards, Rigel_Kent |
Try getcwd(). You will can either do it the most correct way, by allocating a dynamic string, and expanding it if getcwd() truncates. You may be able to use a statically allocated string of length PATH_MAX, but that isn't as guaranteed
|
man getcwd
Quote:
|
Hi,
Thanks for replying. It's solved...I used: Code:
int _MAX_SIZE = 128; Rigel_Kent |
I'm not sure how that can even work, since _MAX_SIZE is not a constant compile-time expression. You are generally supposed to use #define for that in C.
The size you picked is relatively tiny so bad things happening are decently probable. |
Quote:
Code:
char path[_MAX_SIZE]; Code:
char *path; |
Quote:
Kind regards, Rigel_Kent |
PATH_MAX is usually the right constant under Linux.
EXAMPLE: Code:
#include <stdio.h> |
All times are GMT -5. The time now is 10:04 PM. |