Removes the characters that appear in another string from one string.

Source: Internet
Author: User

Define a function, enter two strings, and delete the even strings that appear in the second string from the first string. For example, if you delete the character "auiou" in the second character from the first string "We are students.", the result is "w r stdnts"

Solution: use hash to search.

# Include <stdio. h> void deletestr2fromstr1 (char * str1, char * str2) {If (str1 = NULL | str2 = NULL | * str1 = '\ 0' | * str2 =' \ 0') return; int hash [256]; for (INT I = 0; I <256; ++ I) hash [I] = 0; char * P = str2; while (* P! = '\ 0') hash [* P ++] ++; char * strfront = str1; int Len = strlen (str1); int small =-1; for (INT I = 0; I <Len; ++ I) {If (hash [* (strfront + I)] = 0) str1 [++ small] = * (strfront + I);} str1 [++ small] = '\ 0';} int main () {char str1 [] = "We are students"; char str2 [] = "aeiou"; deletestr2fromstr1 (str1, str2); printf ("% s", str1 ); return 0 ;}


Removes the characters that appear in another string from one string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.