Generation

generate functionMon, 23 Jan 2023

how to replace a string

#include <iostream> void replace(char s[], char oldChar, char newChar) { for (int i = 0; s[i] != '\0'; i++) { if (s[i] == oldChar) { s[i] = newChar; } } } int main(int argc, char const *argv[]) { char s[] = "hello"; replace(s, 'l', 'z'); std::cout << s << std::endl; return 0; }

Questions about programming?Chat with your personal AI assistant