Console primary gameplay under UNIX-like systems

Source: Internet
Author: User

First, it is highly recommended to download a virtual machine and install Ubuntu, and buy "Hi-C language"

Sometimes see the main function of some programs with parameters, such as

int Main (int argc,char argv[])

It was not possible to understand what was behind the argument.

Until....

1#include <stdio.h>2 3 intMainintargcChar*argv[]) {4     if(argc>1){5printf"%s\n", argv[1]);6     }7     return 0;8}

And in the console input

1 gcc test.c-o test2 ./test helloworld!

The first line compiles test.c source code into an executable file test

The second behavior of the main function is to pass in two parameters, assigning the array pointer to the string argv, respectively

Argv[0]= "./test"

argv[1]= "helloworld!"

The ARGC stores the number of parameters, such as argc=2 in the program.

Visible use the console to pass in parameters to the main function.

You can also use the > symbol to redirect the location of the output of the standard output stream.

In general the default output location is our display, but with > can be more flexible. Or the program above?

In bash, enter:

./test helloworld! > output.txt

After the carriage return there is no hint that everything is working properly.

But find the folder where the program, you will find a output.txt file, the content is helloworld!

The same can be used < to redirect the standard input stream, very suitable for a lot of data processing work, you certainly do not want a line of manual knocking data in.

Console primary gameplay under UNIX-like systems

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.