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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: