Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX_PATH_LEN 200 /* sigh */
- typedef char t_path[MAX_PATH_LEN];
- typedef struct {
- t_path next;
- t_path remainder;
- } t_path_next
- t_path_next path_walk_into(t_path path) {
- t_path_next output;
- t_path my_next, my_remainder = "/";
- strncpy(my_next, path, MAX_PATH_LEN);
- strsep(&my_next, my_remainder);
- output.remainder = my_remainder;
- output.next = my_next;
- return output;
- }
- badp@delta:~/blah$ gcc path.c -Wall
- path.c: In function ‘path_walk_into’:
- path.c:39: warning: passing argument 1 of ‘strsep’ from incompatible pointer type
- /usr/include/string.h:559: note: expected ‘char ** __restrict__’ but argument is of type ‘char (*)[200]’
- path.c:41: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
- path.c:42: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
- t_path_next path_walk_into(t_path path) {
- t_path_next output;
- t_path my_path, delim = "/";
- char* my_path_ptr = my_path;
- strncpy(my_path, path, MAX_PATH_LEN);
- strsep(&my_path_ptr, delim); //put a on next slash and advance pointer there.
- if (my_path_ptr == NULL) //no more slashes.
- output.remainder[0] = 0;
- else
- strncpy(output.remainder, my_path_ptr, MAX_PATH_LEN);
- strncpy(output.next, my_path, MAX_PATH_LEN);
- return output;
- }
Add Comment
Please, Sign In to add comment