#include <stdio.h> #include <string.h> void delete_chars(char *string1, char *string2) { int len1 = strlen(string1); int len2 = strlen(string2); int map[256] = {0}; for (int i = 0; i < len2; i++) { map[string2[i]] = 1; } int index = 0; for (int i = 0; i < len1; i++) { if (map[string1[i]] == 0) { string1[index++] = string1[i]; } } string1[index] = '\0'; } int main() { char string1[] = "whatsapp"; char string2[] = "wat"; printf("String1: %s\n", string1); printf("String2: %s\n", string2); delete_chars(string1, string2); printf("After deleting characters from string2 in string1: %s\n", string1); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter