Remove the spaces at both ends of the string trimspace

Source: Internet
Author: User
There is a string beginning or ending with n spaces ("ABCDEFGDDDD") to remove the front and back spaces and return a new string.
int Trimspace (char *bufscr,char *bufdes) {int I=0;char *p=bufscr;//pointer variable, in order not to modify the incoming pointer int len=strlen (BUFSCR); int j=len-1;    int count;//non-null character length int ret=0;//first determine if the incoming pointer is empty if (bufscr==null| | Bufdes==null) {ret=-1;printf ("Func trimspace Err%d:", ret); return ret;} while (Isspace (p[i]) &&p[i]!= ' + ') {i++;} while (Isspace (P[j]) &&j>0) {j--;} count=j-i+1;memcpy (Bufdes,p+i,count);//It is important to note that the difference between a string array and a string is that the end of the string array is ' + '. bufdes[count]= ' + '; return ret;}


Remove the spaces at both ends of the string trimspace

Related Article

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.