C and pointer Chapter 6 Question 2

Source: Internet
Author: User
/*  * C and pointer. Chapter 6: The second question deletes a part of a string, for example, abcdefg. If fgh, CDF, and xabc are input, the deletion fails. If CDE is input, the deletion is successful, get the abfg deletion function prototype: int del_substr (char * stre, char const * substr) stre is the source string to be operated, and substr is the substring to be deleted.  */  # Include <Stdio. h> # Include <Stdlib. h> Int Del_substr ( Char * Stre, Char   Const * Substr ){  Char * STR = Stre; Char * Source = STR;  Char   String = * Source;  Char   Const * Sub_str;  While ( String ! = '  \ 0  '  ) {Sub_str = Substr; While (* Sub_str! = '  \ 0  ' && String ! = '  \ 0  ' & * Sub_str = String  ) {Sub_str ++ ;  String = * ++ Source ;}  If (* Sub_str ='  \ 0  '  ){  //  Matched !!              While (* Source! = '  \ 0  '  ){ * STR ++ = * Source ++ ;}  While (* Str! = '  \ 0 '  ){ * STR ++ = '  \ 0  '  ;}  Return   1  ;} Str ++ ; Source = STR;  String = * Source ;}  Return   0 ;}  Int  Main (){  Char Source [ 100  ];  Char * SRC;  Char Chars [ 100  ]; Printf (  "  Enter a source string: \ n  "  ); Gets (source );  While (1  ) {SRC = & Source; printf (  "  Enter a string to be deleted: \ n  "  ); Gets (chars );  Int Flag = Del_substr (SRC, chars );  If (Flag = 0  ) {Printf (  "  An error occurred while deleting the matched items !! No matching string found !! \ N "  );  Continue  ;} Printf (  "  Matched and deleted !! : \ N  "  ); Printf (  "  % C  " ,* Source );  While (* ++ SRC! = '  \ 0  ' ) Printf (  "  % C  " ,* SRC); printf (  "  \ N  "  );  Break  ;}  Return   0  ;} 

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.