C language in linux. the system function calls the variables in this file.

Source: Internet
Author: User
C language in linux. the system function calls the variables in this file-general Linux technology-Linux programming and kernel information. For details, refer to the following. Sometimes, when writing C language code in linux, we need to call the variables in the C file when we need to execute system commands.

You can refer to the following example (change the test. c file in the current directory to the value of variable B)

# Include

Main ()
{
Int B = 1234, I;
Char c [4];
Memset (c, '0', 4 );
Sprintf (c, "% d", B );
Char a [14] = "mv test. c ";
For (I = 0; I <4; I ++) a [10 + I] = c ;
System ();
Return 0;
}

The idea is to assign the entire command to a char array, including the value of the variable, and then use the system function to execute the content in the char array in the command line.
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.