A nasty Line Mark. Erase it.

Source: Internet
Author: User

I don't know if you will encounter this situation. When you look at people's code in a browser, the code box that comes with the webpage usually has a line mark. Of course, this is convenient for you to view the code,, when you want to paste a piece of code into the IDE and run it, the cup comes. There are several cute numbers at the beginning of each line ......

If it is short, you can delete it manually. However, when you paste dozens or even hundreds of lines of code, you can delete the numbers in one row, it's a fascinating thing ......

This program removes the line mark before each line of code while redirecting the file, and then simply adds indentation (C/C ++ language style ).

How to use:

Put the EXE file generated by code compilation and running, and the code to be compiled (Save As code.txt) in the same directory, and then run the EXE file. The generated code_new.txt is the compiled code.

 

Source code:

# Include <stdio. h> # include <stdlib. h> # include <string. h> char find_last (char s []) {// find the last character of the valid code in each line, that is to say, considering the comments of "//" and "/**/" // of course, I only consider the/**/at the end of each line /**/, that is to say, if the code is embedded in the middle of the/**/, I have to consider it. Please add int I, K; for (I = 0; s [I]; I ++) {If (s [I] = '/' & S [I + 1] = '*' | s [I] = '/' & S [I + 1] = '/') break;} For (k = I-1; k> = 0; k --) {If (s [k] = '') continue; else return s [k];} return-1;} void main () {char STR [10000]; int flag [100000]; int I, j = 0, Space = 0; freop En ("code.txt", "r", stdin); freopen ("code_new.txt", "W", stdout); memset (flag, 0, sizeof (FLAG )); while (gets (STR) {for (I = 0; STR [I]; I ++) {If (STR [I]> = 'A' & STR [I] <= 'Z' | STR [I]> = 'A' & STR [I] <= 'Z' | STR [I] = '#' | STR [I] = '/' | STR [I] = '{' | STR [I] = '}') break; else STR [I] = '';} for (I = 0; STR [I]; I ++) {If (STR [I] = '') continue; else {If (STR [I] = '}') Flag [J] = Flag [J-1]-1; break ;}} for (I = 0; I <4 * flag [J]; I ++) printf (""); int FUC K = 0; for (I = 0; STR [I]; I ++) {If (STR [I]! = ''& Fuck = 0) Fuck = 1; if (fuck! = 0) printf ("% C", STR [I]);} puts (""); char TMP = find_last (STR ); if (TMP = '>' | TMP = ';' | TMP = '}' | TMP = ')' | TMP = ': '| TMP =-1) {flag [J + 1] = Flag [J];} else if (TMP = '{') {flag [J + 1] = Flag [J] + 1 ;}j ++ ;}}


 

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.