Home > C/C++ > Removing trailing Slashes (‘/’)

Removing trailing Slashes (‘/’)

Just adding it up to the blog so that it might help with someone looking for the same….

I had to remove the trailing slashes from the directory paths as that was a requirement of a third party program we were using. Ended up doing it like this:

Where “conf->pg_backup” is the original string
and “newstback” is the changed string after removing trailing slashes…

for(i=0, j=0; conf->pg_backup[i]; ++i)
{
newstback[j++] = conf->pg_backup[i];
}

lenback = strlen(newstback) – 1;

for(;newstback[lenback] == ‘/’ || newstback[lenback] == ‘\t’; lenback–)
;
newstback[lenback +1] = ”;


Shoaib Mir
shoaibmir[@]gmail.com

Categories: C/C++ Tags: ,
  1. No comments yet.