I am coding a program, that deletes all redundant / in the path of the file. In other words ///a/////b should become /a/b.
I can delete all repeated /, but can't fully wrap my head about how to leave only one slash WITHOUT any standard function or indexation operation.
Can someone fix my code, please?
#include <stdio.h>
//      ///a/////b
//      a/b/a
//      aa///b/a
void normalize_path(char *buf) {
    int k = 0, counter = 0;
    for (int i = 0; buf[i]; i++) {
        buf[i] = buf[i + k];
        if (buf[i] == '/') {
            ++counter;
            if (counter > 1) {
                --i;
                ++k;
            } else {
                ++k;
            }
        } else {
            counter = 0;
        }
    }
}
int main() {
    char path[100];
    scanf("%s", path);
    printf("String before the function: %s\n", path);
    normalize_path(path);
    printf("String after the function is used: %s\n", path);
    return 0;
}
 
     
     
     
    