The second day for learning C, and the second day for learning c

Source: Internet
Author: User

The second day for learning C, and the second day for learning c

# Include <stdio. h> # include <windows. h> void main () {MessageBoxA (0, "first C form program", "message", 3); // parameter 1: System pop-up // parameter 2: message content // parameter 3: Title // parameter 4: Dialog Box Type // 0 only the OK button; // 1 The OK cancel button; // 2 terminate retry ignore button // 3 Yes No cancel button getchar ();}

2. ShellExecuteA

 

# Include <windows. h> void main () {// _ In_opt _ HWND hwnd, // system start // _ In_opt _ LPCSTR lpOperation, // open // _ In _ LPCSTR lpFile, // command // _ In_opt _ LPCSTR lpParameters, // default 0 // _ In_opt _ lpstr lpDirectory, // default 0 // _ In _ INT nShowCmd // 0 hide 3 maximize 6 minimize other normal ShellExecuteA (0, "open", "notepad", 0, 0, 3 ); // open notepad ShellExecuteA (0, "open", "tasklist", 0, 0, 1) to the maximum extent; // execute the tasklist command ShellExecuteA (0, "open ", "www.baidu.com", 0, 0, 3); // open the Baidu website ShellExecuteA (0, "open", "C: \ Users \ Administrator \ Desktop \ cmd2.txt ", 0, 0, 3); // open the txt file ShellExecuteA (0," print "," C: \ Users \ Administrator \ Desktop \ translation .docx ", 0, 0, 0); // call printer printing}

 

3. Two memory consumption methods

# Include <windows. h> # include <stdlib. h> void main () {// Method 1: while (1) {malloc (10000000); // malloc allocates 1000000 bytes of Sleep (1000 ); // wait for one second} // Method 2: while (1) {ShellExecuteA (0, "open", "notepad", 0, 0 ); // slowly open notepad Sleep (1000) in the background; // wait for one second }}

4. Print the eleven methods of hello china

 

# Include <stdio. h> void main () {// Method 1: printf ("hello china \ n ");

// Method 2:
Printf ("% s \ n", "hello china ");

// Method 3:
Printf ("% c \ n", 'h', 'E ', 'l', 'l', 'O', '', 'C', 'h', 'I', 'n', 'A ');

// Method 4:
Printf ("% c \ n", 104,101,108,108,111, '', 99,104,105,110, 97 ); // Method 5: putchar ('H'); putchar ('E'); putchar ('l'); putchar ('O '); putchar (''); putchar ('C'); putchar ('H'); putchar ('I'); putchar ('n '); putchar ('A'); putchar ('\ n ');
// Method 6: putchar (104); putchar (101); putchar (108); putchar (108); putchar (111); putchar (''); putchar (99); putchar (104); putchar (105); putchar (110); putchar (97); putchar ('\ n'); // Method 7: putchar (0150); putchar (0145); putchar (0154); putchar (0154); putchar (0157); putchar (''); putchar (0143 ); putchar (0150); putchar (0151); putchar (0156); putchar (0141); putchar ('\ n'); // Method 8: putchar ('\ 150'); putchar ('\ 145'); putchar ('\ 154'); putchar ('\ 154'); putchar ('\ 157 '); putchar (''); putchar ('\ 143'); putchar ('\ 150'); putchar ('\ 151'); putchar ('\ 156 '); putchar ('\ 141'); putchar ('\ n'); // Method 9: putchar (' \ x68 '); putchar (' \ x65 '); putchar ('\ x6c'); putchar (' \ x6c'); putchar ('\ x6f'); putchar (''); putchar (' \ x63 '); putchar ('\ x68'); putchar ('\ x69'); putchar ('\ x6e'); putchar ('\ x61'); putchar ('\ n '); // Method 10: putchar (0x68); putchar (0x65); putchar (0x6c); putchar (0x6c); putchar (0x6f); putchar (''); putchar (0x63); putchar (0x68); putchar (0x69); putchar (0x6e); putchar (0x61 ); putchar ('\ n ');

// Method 11
Puts ("hello china"); // input a string to print the string
Getchar ();}

 

5. escape characters

Print \, "Use \, \", print 'Use \' or "'"

Octal \ 3-digit number starting with 0

Number starting with 0x in hexadecimal format

6. Differences between sprintf and printf

1. sprintf will not print on the console, but assign values to the variables, while printf prints the strings on the screen.

  

# Define _ CRT_SECURE_NO_WARNINGS // close the security check # include <stdio. h> # include <stdlib. h> void main () {char str [50]; sprintf (str, "% s", "notepad"); system (str); // open notepad}

2. Execute the command to initialize the string

# Define _ CRT_SECURE_NO_WARNINGS // close the security check # include <stdio. h> # include <stdlib. h> void main () {int num; printf ("enter a number:"); scanf ("% d", & num ); // receives the input value char str [50]; sprintf (str, "for/l % I in (, % d) do start calc", num ); system (str );}

 

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.