I think that is problem with convertin char to const char*
How can I to convert char* to const char*. I tried with cast but system output error.
My code is: Quote:
Quote:
int inotify_add_watch(int fd, const char *pathname, uint32_t mask); If I write in inotify_add_watch function directly any directory string: wd = inotify_add_watch(fd, "/tmp", IN_CREATE | IN_MODIFY | IN_DELETE); then program run without problems. I want program in C, then I cannot use c_str() C++ function. How can I solve this problem? Thanks, Savio |
Maybe you have to delete the new line character "\n" from dir, just a thought
|
How can I split and truncate dir from "\n"?
|
I don't know, you could replace the newline char with a null:
dir[strlen(dir) -1] = '\0'; |
Quote:
|
I think keefaz is correct you do not add a new line to the printf statements yet there is one there in the output. The cast from char* to char const* is implicit, the warning about _GNU_SOURCE is due to adding it on the command line and also in the code, one of these should be removed. This is a much better request for help :)
edit: Oops I never refreshed the screen before posting |
I typed:
Quote:
|
Note however, that with you code, you use non-terminated with '\0' strings, that means weird bugs could happen...
strlen returns the number of chars not including the terminating \0, you have to malloc the number of chars you want + the terminating \0 and man strncpy: Quote:
dir = malloc(strlen(token)); strncpy(dir, token, strlen(token) - 1); |
Quote:
|
All times are GMT -5. The time now is 04:18 PM. |