Untitled
#include <iostream> #include <cstring> using namespace std; void replaceChar(char *str, char a) { for (int i = 0; i < strlen(str); i++) { if (str[i] == a) { for (int curPos = i; curPos < strlen(str); curPos++) { str[curPos] = str[curPos + 1]; } } } } int main() { char str[] = "ghephetnhe"; char repl = 'h'; replaceChar(str, repl); cout << str << endl; return 0; }
Leave a Comment