Delete Extra blank characters and blank lines in the string (implemented in C)

Source: Internet
Author: User



(2) You are not allowed to apply for a new space.
(3) spaces, tabs, and blank lines are not allowed at the beginning and end of the processed string.
(4) If the original string contains consecutive spaces and horizontal tabs, only one space is required for the processed string.
(5) If the original string contains consecutive spaces, horizontal tabs, and empty rows, the processed string only needs to store one empty row.


Changed after Reminder ):

remove_extra_space (* state =;
      i =;
      j =;
 
     (; str [i]! =; ++ (str [i] == || str [i] == (state == || state == || state == (state == str [j ++] = state = (str [i] == (state == || state == (state == str [j-] = state = (state == str [j ++] = state =
              str [j ++] = state = (state == || state ==-str [j] =}
 Refer to the idea and playerc code to use pointer version (recommended):

  remove_extra_space (* * sp = * prev =
     (* str && (* str == || * str == || * str == ++
     (; * str; ++ (*: * str = (* prev == || * prev ==
                        (* prev == (* prev == * prev =
         prev = * sp ++ = *
     (prev && * prev && (* prev == || * prev ==-* sp =}
Refer to the code written by playerc: http://www.cnblogs.com/playerc/p/3217355.html

Finally, thank you to all the friends who provided valuable advice!

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.