Version 1 of the C program that can print its source code

Source: Internet
Author: User

Version 1

 
# Include <stdio. h>IntMain (){Char* P ="# Include <stdio. h> % C int main () {char * P = % C % S % C; printf (p, 10, 34, p, 34 );}"; Printf (p,10,34, P,34);}

Rating:

This implementation is very subtle. The first p transmits the current string as the printf format string, and uses the following parameters to replace the placeholder in the format string (% C,% C % S % C) To generate a new string, the first% CReplaced with a carriage return (ASCII value of 10)% C % S % CIs replaced:"# Include <stdio. h> % C int main () {char * P = % C % S % C; printf (p, 10, 34, p, 34 );}"(The ASCII code value of 34 is double quotation marks,% SThen replace it with P. printf copies the replaced string to the new memory block without modifying the format string pointed to by P)

 

Note:

In Linux, there is a command line tool for viewing the ASCII code value table. In ubuntu, you can install the ASCII code through sudo apt-Get install. Start the command:

$ ASCII

 Dec hex dec hex 0 00 NUL 16 10 DLE 32 20 30 30 0 64 40 @ 80 50 p 96 60 '112 70 P 1 01 Soh 17 11 DC1 33 21! 49 31 1 65 41 A 81 51 Q 97 61 A 113 71 Q 2 02 STX 18 12 DC2 34 22" 50 32 2 66 42 B 82 52 r 98 62 B 114 72 R 3 03 etx 19 13 DC3 35 23 #51 33 3 67 43 C 83 53 s 99 63 C 115 73 s 4 04 EOT 20 14 dc4 36 24 $52 34 4 68 44 d 84 54 t 100 64 d 116 74 T 5 05 Enq 21 15 Nak 37 25% 53 35 5 69 45 E 85 55 U 101 65 E 117 75 U 6 06 ack 22 16 SYN 38 26 & 54 36 6 70 46 F 86 56 v 102 66 F 118 76 V 7 07 Bel 23 17 etb 39 27 '55 37 7 71 47g 87 57 W 103 67g 119 77 W 8 08 BS 24 18 can 40 28 (56 38 8 72 48 h 88 58x104 68 H 120 78X9 09 HT 25 19 em 41 29) 57 39 9 73 49 I 89 59 y 105 69 I 121 79 y10 0a lf 26 1A sub 42 2a * 58 3A: 74 4A J 90 5A Z 106 6a J 122 7A Z 11 0b VT 27 1B ESC 43 2B + 59 3B; 75 4B K 91 5B [107 6B K 123 7b {12 0C FF 28 1C FS 44 2C, 60 3C <76 4C l 92 5C \ 108 6C L 124 7C | 13 0d Cr 29 1D GS 45 2D-61 3D = 77 4D M 93 5D] 109 6D M 125 7d} 14 0e so 30 1E Rs 46 2E. 62 3E> 78 4E N 94 5E ^ 110 6e n 126 7E ~ 15 0f Si 31 1f us 47 2f/63 3f? 79 4f o 95 5f_ 111 6f o 127 7f del

 

 

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.