i trying remove characters char pointer , store them in new char pointer variable let's "temp". have this:
char *test = "1@2#3$4%5^6&7*8!9@1#0"; char *temp = ""; then remove "@,#,$,%,^,*,!,@,#," , place new values of "12345678910" *temp. make temp equal "12345678910".
is possible?
i have been doing string need char pointers. here how have done string:
std::string str("1@2#3$4%5^6&7*8!9@1#0"); std::string temp(""); char chars[] = "@#$%^&*!"; (unsigned int = 0; < strlen(chars); ++i) { str.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); } temp = str; so see here doing strings cannot seem away asigning char * variable test string because illegal conversion. why able set char * variables equal string so?
char *test = "123456789"; however illegal?
std::string str("1@2#3$4%5^6&7*8!9@1#0"); char chars[] = "@"; (unsigned int = 0; < strlen(chars); ++i) { str.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); } char *test = str; //illegal point thank time.
change
char *test = str; into:
char *test = str.c_str(); c_str method creates c style char array original string you.
edit: more safe way, copy of c string obtained:
#include <cstring> #include <cstdlib> ... char *test = strdup(str.c_str()); ... // process string free(test);
Comments
Post a Comment