Guest User

Untitled

a guest
Jan 5th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #include <string.h>
  4.  
  5. void normalize_path(char *buf)
  6. {
  7.     char *ptr = buf;
  8.     int first = 1, flag = 0;
  9.  
  10.  
  11.     while (*ptr)
  12.     {
  13.         if (*ptr == '/')
  14.         {
  15.             flag = 1;
  16.  
  17.             while (*ptr)
  18.             {
  19.                 if (*ptr != '/')
  20.                 {
  21.                     break;
  22.                 }
  23.                 ptr++;
  24.             }
  25.         }
  26.  
  27.         if (flag)
  28.         {
  29.             *buf = *ptr;
  30.             buf++;
  31.         }
  32.         else
  33.         {
  34.             buf++;
  35.         }
  36.  
  37.         ptr++;
  38.  
  39.         // "a///b///c/d"
  40.     }
  41.  
  42.     buf++;
  43.     *buf = '\0';
  44. }
  45.  
  46. int main()
  47. {
  48.     char a[] = "a////b///c/d";
  49.  
  50.     normalize_path(a);
  51.  
  52.     printf("%s\n", a);
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment