PDA

View Full Version : more on strings



Strut
02-02-2002, 04:07 PM
okay... say I have a string.

char *str;

str="Hello";

I want to remove a certain character completely from it, on a certain spot. for example, str[0] would equal H. perhaps if str[0] equals H I want to remove str[0] comepletey. making the value, "ello". any help? thanks.

Nick
02-02-2002, 10:00 PM
If you want to remove the first one.



#include <string.h>
#include <stdio.h>
int main()
{
char *str = "hello";
str++;
puts( str );
return 0;
}


If you want to modify what str points to then write
char str[] = "Hello";

This will most likely crash on linux as str is allowed to be
stored in constant data section:


#include <string.h>
#include <stdio.h>
int main()
{
char *str = "hello";
str[3] = 'A';
str++;
puts( str );
return 0;
}

Strut
02-03-2002, 12:16 PM
thakns guys, for your help. I really appreciate it.