This topic is now archived and is closed to further replies.

remove part or char *...

This topic is 5272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

a char* is an array so you can loop it like an array. Something like :

for (int j = (strlen(myStr) - 1); j >= 0; --j)
if (myStr[j] == '.')
myStr[j] = '\0';

of course i wrote that off the top of my head so there is bound to be some random error in there but you get the idea. If you replace the '.' with the null char '\0' then the string will end there so .tga will dissapear


(NOTE : found one random error already )

[edited by - kaysik on July 6, 2003 5:49:48 AM]

Share this post

Link to post
Share on other sites
It depends how it is declared. If it is like this:
char* texture="texture.tga";
Then no you can''t do that since the above is the exact same as this:
const char* texture="texture.tga";
However, if you declare it like this:
char texture[]="texture.tga";
Then kaysik''s method will work.

-If you see this image I may or may not be online
My website

Share this post

Link to post
Share on other sites
Using C (I'm not familiar with C++) the simplest way would be

*strrchr(myString, '.') = '\0';  

Assuming you did one of the following

char myString[] = "texture.tga"; 


char *myString = malloc(strlen("texture.tga") + 1);
strcpy(myString, "texture.tga");

As mentioned before,
char *myString = "texture.tga";  
is much like
const char *myString = "texture.tga";  
except that it'll only fail at runtime on some implementations (but not necessarily other implementations).

EDIT: Fix tags and realize that my C++ idea doesn't work

[edited by - Way Walker on July 6, 2003 3:21:33 PM]

Share this post

Link to post
Share on other sites