Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 01-05-2006, 01:46 PM   #1 (permalink)
Alpha Geek
 
Join Date: Feb 2005
Posts: 959
Default C++ probs...


hi,

i am working in FC4, gcc3.2 compiler. pls help me doing this.

i have a string say,

string str1 = "/home/legolas/contents/EP1"

now i hav to find the location of the last occurance of "/" character from this string (22 in this case with index 0) and then i hav to get teh string upto that...

that is, /home/legolas/contents/

how do i do this?

/legolas
__________________
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
legolas is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 01-05-2006, 06:58 PM   #2 (permalink)
Alpha Geek
 
Join Date: Dec 2003
Posts: 780
Default Re: C++ probs...

i=strlen(str1);
while(i)
{
if(str1[--i]=='\\') // Escape character for \
return i;
}

This will give you the value of i (by traversing the string from end to start, and returning the position of the first / it meets).

Now you can copy the string uptill this position.
__________________
Hardware - Celeron 266 MHz, 128MB RAM, Intel i740 8MB RAM
Software - Slackware Linux 10.1; Archlinux 0.7; Windows 98 SE
Humanware - GS/CS C++ L+++ w b+++ DI+ D+ e
ujjwal is offline  
Old 01-05-2006, 07:34 PM   #3 (permalink)
Wise Old Owl
 
vignesh's Avatar
 
Join Date: Jul 2004
Location: Chennai
Posts: 1,659
Default Re: C++ probs...

One question on bash ujjwal... read accepts input from the std input ok and -s stops the echoing.. (i.e) the entered text is not displayed on the screen .. Now I have a menu and get a number as the option How to make it go to the req pos in the if/case without pressing return ?

So when I press a number the corresponding code is executed without typing the number and pressing the enter key.
vignesh is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by topgear

Advertisement




All times are GMT +5.5. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2