亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
1234下一頁(yè)
最近訪問板塊 發(fā)新帖
查看: 9857 | 回復(fù): 32
打印 上一主題 下一主題

給初學(xué)者玩的一個(gè)時(shí)鐘的小程序 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2006-09-27 10:52 |只看該作者 |倒序?yàn)g覽
同事問起一個(gè)在終端顯示時(shí)間嘀噠走的程序,反正沒什么事就寫了一個(gè),非常簡(jiǎn)單,給初學(xué)者玩玩

  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <unistd.h>

  4. int main ()
  5. {
  6.         while (1) {
  7.                 time_t sec  = time(NULL);
  8.                 struct tm t = *localtime(&sec);

  9.                 printf("\x1b[2J");      /* clear screen and home cursor */
  10.                 printf("\x1b[31;40m");  /* red foreground, black background */
  11.                 printf("\x1b[11;29H");  /* moves cursor to line 11, column 29 */
  12.                 printf("+-----^--^-----+\n");
  13.                 printf("\x1b[12;29H");
  14.                 printf("|\t%02d:%02d:%02d:  |\n", t.tm_hour, t.tm_min, t.tm_sec);
  15.                 printf("\x1b[13;29H");
  16.                 printf("+-------V------+\n");
  17.                 sleep(1);
  18.         }

  19.         return 0;
  20. }
  21. /* reference: ANSI Escape Sequences
  22. * compile:   gcc mytime.c -o mytime
  23. * usage:     ./mytime
  24. */

復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2006-09-27 11:13 |只看該作者
真棒,就是不懂那些printf是干什么用的

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2006-09-27 11:18 |只看該作者
有簡(jiǎn)單注釋
搜索一下ANSI Escape Sequences 內(nèi)容不是很多
有時(shí)候調(diào)試程序時(shí)的不同輸出信息加入顏色還是很有用的

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2006-09-27 13:25 |只看該作者
樓主這些printf在dos下也可以用嗎?

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2006-09-27 13:45 |只看該作者
dos下也可以
跟ansi.sys相關(guān)

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2006-09-27 14:53 |只看該作者
嗯。不錯(cuò)。以前記過覺得很好玩,就是有時(shí)偶爾想用了,又找不到這些控制字了,呵呵!
個(gè)人比較喜歡這東東。

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2006-09-27 15:17 |只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2006-09-27 15:50 |只看該作者
不懂printf("\x1b[2J");里面的   1b[2J  是什么東西啊,高手指點(diǎn)指點(diǎn)

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2006-09-27 16:22 |只看該作者
1B是ESC的十六進(jìn)制

  1. ANSI Escape Sequences

  2. What ANSI escape sequences can be used?

  3. ANSI escape sequences provide cursor and screen control in OS/2 character
  4. mode sessions.  By default ANSI support is turned ON (although it may be
  5. turned off with the command ANSI OFF).  ANSI support is also available in
  6. DOS sessions if the device driver ANSI.SYS is loaded.  See the online
  7. Command Reference for details.

  8. The following ANSI escape sequences are available:

  9. Key      
  10. ESC       Refers to ASCII code 27 (i.e. the Escape key)
  11. #         Replace with the appropriate number
  12. ....      Replace with additional attributes, if desired


  13. Escape Code Sequence          Function
  14. Cursor Controls               
  15. ESC[#;#H or ESC[#;#f          Moves cursor to line #, column #
  16. ESC[#A                        Moves cursor up # lines
  17. ESC[#B                        Moves cursor down # lines
  18. ESC[#C                        Moves cursor forward # spaces
  19. ESC[#D                        Moves cursor back # spaces
  20. ESC[#;#R                      Reports current cursor line and column
  21. ESC[s                         Saves cursor position for recall later
  22. ESC[u                         Return to saved cursor position
  23. Erase Functions               
  24. ESC[2J                        Clear screen and home cursor
  25. ESC[K                         Clear to end of line
  26. Set Graphics Rendition        
  27. ESC[#;#;....;#m               Set display attributes where # is
  28.                                0 for normal display
  29.                                1 bold on
  30.                                4 underline (mono only)
  31.                                5 blink on
  32.                                7 reverse video on
  33.                                8 nondisplayed (invisible)
  34.                                30 black foreground
  35.                                31 red foreground
  36.                                32 green foreground
  37.                                33 yellow foreground
  38.                                34 blue foreground
  39.                                35 magenta foreground
  40.                                36 cyan foreground
  41.                                37 white foreground
  42.                                40 black background
  43.                                41 red background
  44.                                42 green background
  45.                                43 yellow background
  46.                                44 blue background
  47.                                45 magenta background
  48.                                46 cyan background
  49.                                47 white background
  50. ESC[=#;7h                     Put screen in indicated mode where # is
  51.                                0 for 40x25 black and white
  52.                                1 40x25 color
  53.                                2 80x25 black and white
  54.                                3 80x25 color
  55.                                4 320x200 color graphics
  56.                                5 320x200 black and white graphics
  57.                                6 640x200 black and white graphics
  58.                                7 to wrap at end of line
  59. ESC[=#;7l                     Resets mode # set with above command
  60. Keyboard Reassignments        
  61. ESC[#;#;....#p                The first ASCII code defines what is to be
  62.                                changed; the remaining codes define what it
  63.                                is to be changed to; strings are permitted.
  64.                               
  65.                                Examples:
  66.                                ESC[65;81p - A becomes Q
  67.                                ESC[81;65p - Q becomes A
  68.                                ESC[0;68;"dir";13p - Assign the F10 key to
  69.                                a DIR command.
  70.                                The 0;68 portion is the extended ASCII code
  71.                                for the F10 key and 13 is the ASCII code
  72.                                for a carriage return.
  73.                                Other function key codes: F1=59, F2=60,
  74.                                F3=61, ... F10=68.


  75. You can use ANSI escape sequences in the PROMPT environment variable to
  76. create complex command line prompts.  See the online Command Reference
  77. (under PROMPT) for details.

  78. For example, if you have a color monitor, try editing your CONFIG.SYS
  79. file so that

  80. SET PROMPT=$e[32;40m$e[1m[$P]$e[0m
  81.   

  82. to obtain a more colorful OS/2 command line prompt.  (Case is significant
  83. in the example given.)  You can do the same for your DOS sessions if you
  84. edit PROMPT in AUTOEXEC.BAT, assuming you have ANSI.SYS loaded.  Note
  85. that the $i portion of your PROMPT will enable the help line at the top
  86. of the window or screen.  It is not included in the example above.

復(fù)制代碼

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2006-09-27 16:58 |只看該作者

回復(fù) 9樓 mike_chen 的帖子

你真棒,懂的真多,我平常都用不到這些東西,我也不清楚這是做什么用的,什么時(shí)候該用噢?為啥要用十6進(jìn)制呢,咋不用其它進(jìn)制呢,嘻嘻...ANSI Escape Sequences是誰(shuí)做的,什么時(shí)候要用到這個(gè)東西呢?

[ 本帖最后由 蝸大牛牛 于 2006-9-27 17:04 編輯 ]
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP