Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Get Variable Value ?

Status
Not open for further replies.

itlike

MIS
Oct 18, 2002
4
0
0
MY
I got a string 'path' (see below)

path = "/home/abcd/public_html/a.cgi"

How to filter 'a.cgi' from the 'path' string?
My espected value should be "/home/abcd/public_html/".

Another word, how to copy the string from the last '/' ?
I don't want 'a.cgi' or 'b.cgi' etc from this new
value.

Thank.
 
for (i=strlen(path)-1;i>=0'i--)
if (path='/')
break;
strcpy(filename,path+i+1);
 
hi ..

if you want to get to the last '/' in your code you can try using strrchr [this scans the string for the last occurance of a given character].

char path[] = "/home/abcd/public_html/a.cgi";
char *ptr, c = '/';

ptr = strrchr(path, c);
if (ptr)
{
/* do what you want to do here */ }
else
printf("The character was not found\n");
return 0;

br:
 
Hi,

I think there is a function called splitpath() that may help you out as well. I can't remeber off hand what the args are and it may not be a standard function, but you can find out about it searching in VC++ 6.0.

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top