Deletes characters at the specified position in a string.

Source: Internet
Author: User

Deletes characters at the specified position in a string.

/*************************************** * ******************************** All Rights Reserved (C) 2015, Wu Yingqiang. ** File name: DelPosChar. c * File ID: none * Content Abstract: Delete the character at the specified position in the string * Other Description: none * Current version: V1.0 * OPERATOR: Wu Yingqiang * completion date: 20150115 *************************************** * *******************************/# include
 
  
# Include
  
   
# Include
   
    
/*************************************** * ******************************** Function description: delete the character at the specified position in the string * input parameter: str -- string to be operated; pos -- location of the character to be deleted * output parameter: str -- string after the character is deleted * return value:-1 -- failed, 0 -- Success * Other Instructions: no * modified date version number modifier content *********************** **************************************** * ******/int DelPosChar (char * str, int pos) {I F (str = NULL) {return-1;} int len = strlen (str); for (int I = pos; I <len; I ++) {str [I-1] = str [I];} str [len-1] = '\ 0'; return 0 ;} /*************************************** * ******************************** function description: main function * input parameter: none * output parameter: none * return value: none * Other description: no * modified date version number modifier content *********************** ************ * **********************************/Void main () {int ret = 0; char buf [] = "hellokityManGood"; // test string printf ("% s \ n", buf); ret = DelPosChar (buf, 1 ); if (ret! = 0) {return;} printf ("% s \ n", buf); ret = DelPosChar (buf, 2); if (ret! = 0) {return;} printf ("% s \ n", buf); ret = DelPosChar (buf, 3); if (ret! = 0) {return;} printf ("% s \ n", buf); system ("pause ");}
   
  
 

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.