Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #define MAX_PATH_LEN 200 /* sigh */
  2. typedef char t_path[MAX_PATH_LEN];
  3.    
  4. typedef struct {
  5.     t_path next;
  6.     t_path remainder;
  7. } t_path_next
  8.  
  9. t_path_next path_walk_into(t_path path) {
  10.     t_path_next output;
  11.  
  12.     t_path my_next, my_remainder = "/";
  13.     strncpy(my_next, path, MAX_PATH_LEN);
  14.  
  15.     strsep(&my_next, my_remainder);
  16.  
  17.     output.remainder = my_remainder;
  18.     output.next = my_next;
  19.     return output;
  20. }
  21.    
  22. badp@delta:~/blah$ gcc path.c -Wall
  23. path.c: In function ‘path_walk_into’:
  24. path.c:39: warning: passing argument 1 of ‘strsep’ from incompatible pointer type
  25. /usr/include/string.h:559: note: expected ‘char ** __restrict__’ but argument is of type ‘char (*)[200]’
  26. path.c:41: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
  27. path.c:42: error: incompatible types when assigning to type ‘t_path’ from type ‘char *’
  28.    
  29. t_path_next path_walk_into(t_path path) {
  30.     t_path_next output;
  31.     t_path my_path, delim = "/";
  32.     char* my_path_ptr = my_path;    
  33.     strncpy(my_path, path, MAX_PATH_LEN);
  34.  
  35.     strsep(&my_path_ptr, delim); //put a on next slash and advance pointer there.
  36.  
  37.     if (my_path_ptr == NULL) //no more slashes.
  38.         output.remainder[0] = 0;
  39.     else
  40.         strncpy(output.remainder, my_path_ptr, MAX_PATH_LEN);
  41.     strncpy(output.next, my_path, MAX_PATH_LEN);
  42.  
  43.     return output;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top