Original Post
Which function and header do i need to replace characters in a string ?

www.web-discovery.net

www.web-discovery.net

char kill = 'a';
char replace = 'z';
for ( int i = 0; i < strlen(str); i++ )
if ( str[i] == kill )
str[i] = replace;

quote:
Original post by penetrator
and if i should replace, for example, "......" with "..", what the code would be ?
char * found = 0;
char formed[60] = {0};
const char text[60] = "Some very long string incorporating a...... triple ellipsis";
const char * trellipsis = "......";
found = strstr( text, trellipsis );
if( found != 0 && found != text )
{
strncpy( formed, text, (found - text) );
strcat( formed, ".." );
strcat( formed, (found + 6) );
}
quote:
Original post by penetrator
Still not working. All i want to do is to store string values which are separated by spaces, sometimes 2, sometimes 4 or 5 spaces, into 1 array...
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more