3_in windows, use the batchcompute file _ to remove the leading numbers in the C source code indicating the row number.

Source: Internet
Author: User

Paste in the gardenCodeSome people often paste the code with a line number in front of it, copy it, paste it into the code editor, and there are a lot of numbers in front of it.

Before compilation, You need to delete all these numbers before compilation, and delete dozens of lines of code. If there are thousands of lines of code, it will be troublesome.

Exp: C with a leading row numberSource code

1# Include <stdio. h>
2
3 IntMain (IntArgc,Char** Argv)
4{
5Printf ("Hello world!");
6
7 Return 0;
8}

If there is a simple way to remove the line numbers before the code, it will help improve learning efficiency. Since everyone knows programming, they will think of using programming methods.

This function is implemented. For example, you can use C to write a small number of read/write files.ProgramTo implement this function. But this is troublesome. Is there a simpler method?

The answer is: yes.

You can use the functions provided by the command line. Based on the above requirements, I use the command line to achieve a simple removal of the C language code in front of the row number batch processing. Batch Processing is given below

File Source Code:

 @ Echo   Off 

Title C language code removal of leading numbers Batch Processing
Echo .
Echo .
Echo **************************************** ***********************
Echo .
Echo .
Echo Welcome to -- C language code to remove leading digital batch processing -- Tool
Echo .
Echo .
Echo Author: volcanol
Echo Version: v0.0
Echo QQ: 164498180
Echo Email: lilinly225
Echo Blog: http://www.cnblogs.com/volcanol/
Echo .
Echo .
Echo **************************************** ************************
Echo .
Echo .
Echo Press any key to continue .........
Echo .
Echo .
Pause > NUL

:: Accept user input file name
CLS
Echo .
Echo Enter the complete path and file name (only the file name can be entered in the current folder ):
Echo .
Set /P file =

:: Determine whether a file exists
If Exist % File % Goto Goon

:: The file to be edited does not exist. If prompted, exit.
Echo .
Echo .
CLS
Echo **************************************** **************************
Echo .
Echo .
Echo The file you want to edit does not exist. Check whether the path and file name are correct!
Echo .
Echo Thanks for using the -- C language code to remove the leading digital batch processing -- Tool
Echo .
Echo Press any key to exit ................
Echo .
Echo .
Echo **************************************** **************************
Pause > NUL
Exit

:: Execute the following statement if a file exists.
: Goon
Echo .> De_pre_num.c
For /F "tokens = 2-30" % I in (% file %)Do Echo % I % J % K % L % m % N % o % P % Q % R % S % T % u % % v % w % x % Y % z> de_pre_num.c
CLS
Echo **************************************** **************************
Echo .
Echo .
Echo The processed file is successfully processed and saved in : De_pre_num . C
Echo .
Echo Thanks for using the -- C language code to remove the leading digital batch processing -- Tool
Echo .
Echo Press any key to exit .........
Echo .
Echo .
Echo **************************************** **************************
Pause > NUL

Exp: Below is the C language code with leading numbers.

 1   /*  
2 Strtoint: converts a string to an integer.
3 */
4 # Include <stdio. h>
5 Unsigned Long Int Str_to_int ( Const Char * Source );
6 Int Main ( Int Argc Char * Argv [])
7 {
8 Char STR [ 5 ] = " 1234 " ;
9 Unsigned Long Int Test;
10 Test = str_to_int (STR );
11 Printf ( " % D \ n " Test );
12 Return 0 ;
13 }
14 /*
15 Function:
16 Converts a string consisting of 0-9 characters to an integer.
17 Function prototype:
18 Unsigned long int str_to_int (const char * Source)
19 Function parameters:
20 Char * Source: the first address of the string.
21 Return Value:
22 Int value after conversion
23 Exception:
24 When a null pointer is passed or the function cannot return the correct value
25 */
26 Unsigned Long Int Str_to_int ( Const Char * Source)
27 {
28 Unsigned Long Int Result = 0 ;
29 While ( ' \ 0 ' ! = * Source)
30 {
31 Result = (* Source + result- ' 0 ' )* 10 ;
32 ++ Source;
33 }
34 Return Result/ 10 ;
35 }

Exp: Below is the C language code after batch processing:

 /*  
Strtoint: converts a string to an integer.
*/
# Include <stdio. h>
Unsigned Long Int Str_to_int ( Const Char * Source );
Int Main ( Int Argc Char * Argv [])
{
Char STR [ 5 ] = " 1234 " ;
Unsigned Long Int Test;
Test = str_to_int (STR );
Printf ( " % D \ n " Test );
Return 0 ;
}
/*
Function:
Converts a string consisting of 0-9 characters to an integer.
Function prototype:
Unsigned long int str_to_int (const char * Source)
Function parameters:
Char * Source: the first address of the string.
Return Value:
Int value after conversion
Exception:
When a null pointer is passed or the function cannot return the correct value
*/
Unsigned Long Int Str_to_int ( Const Char * Source)
{
Unsigned Long Int Result = 0 ;
While ( ' \ 0 ' ! = * Source)
{
Result = (* Source + result- ' 0 ' )* 10 ;
++ Source;
}
Return Result/ 10 ;
}

When I was learning Linux, I knew that there was a regular expression. It seemed like there was a regular expression in VB script or JScript, which could be used to process text files. I didn't know much about the command line before, now

It is found that the batch processing under Win is good and can implement many functions.

 

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.