I am trying to make a function that takes a string and removes all occurences of a specified character then returns the new string. The code I wrote generates an error, and I am having no luck debugging the problem. Can someone point me in the write direction? I am using visual studio 2003.
Code:char* remove(char *str, char c) { char *str2=""; while(*str != '\0') { if(*str!=c) { *str2=*str; } str++; str2++; } return str2; } int _tmain() { char* str = "This is a test"; char c= ' '; remove(str, c); // cout<<endl<<remove(str, c); }



LinkBack URL
About LinkBacks


