• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 60  文章 - 5  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(2)

            隨筆分類(42)

            隨筆檔案(60)

            文章檔案(2)

            我收藏的博客

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            the formulation of a problem is often more essential than its solution,which may be merely a matter of mathematical or experimental skill.
            愛因斯坦,提出一個(gè)問題往往比解決一個(gè)問題更重要。
            posted @ 2012-01-04 16:06 黃劍父 閱讀(180) | 評(píng)論 (0)編輯 收藏
            一、tcmalloc
            1、tcmalloc是什么?
            2、安裝tcmalloc

            二、mysql
            1、mysql的編譯

            2、把tcmalloc編譯到mysql中

            三、memcache
            1、memcache是什么?
            2、安裝memcache
            posted @ 2011-11-22 08:52 黃劍父 閱讀(280) | 評(píng)論 (0)編輯 收藏
            官網(wǎng)地址:http://scratch.mit.edu
            Scratch是一種計(jì)算機(jī)編程語言,利用它可輕松地創(chuàng)建自己的互動(dòng)故事,動(dòng)畫,游戲,音樂和藝術(shù)- 和在網(wǎng)絡(luò)上分享你的作品。 當(dāng)學(xué)生創(chuàng)建和共享自己的Scratch動(dòng)畫時(shí),他們能學(xué)習(xí)到重要的數(shù)學(xué)和計(jì)算知識(shí),同時(shí)也得到創(chuàng)造性的思考,系統(tǒng)推理,和協(xié)同工作的機(jī)會(huì)。

            為什么要用Scratch學(xué)習(xí)編程?
            1、Scratch上手非常容易,適于8歲以上孩子,成人也可以玩。積木,我想大多數(shù)人應(yīng)該有玩過吧,沒實(shí)際玩過至少也聽說過吧。用Scratch編程就像玩積木一樣,非常簡單,把像一個(gè)個(gè)積木一樣的腳本命令,按照一定的邏輯堆積起來,就可以做出自己的動(dòng)畫或游戲了。有圖才有真相,各位看官請(qǐng)先看圖。


            2、Scratch簡單,但能做很多事。你可以到官網(wǎng)看看一些優(yōu)秀的作品,就知道Scratch能做些什么呢。
            3、Scratch雖然不用你去敲代碼,但它同其它計(jì)算機(jī)語言的編程思想是完全一樣的,和C,C++,Java的編程思想沒什么兩樣。如果你懂C、C++或Java,那些堆積起來的腳本,也是可以翻譯成C、C++、Java代碼的,并且非常簡單,絕對(duì)要比英語翻譯簡單很多很多。
            4、Scratch是免費(fèi)的,可以在Mac,Windows和Linux上運(yùn)行,并且軟件的語言是可以設(shè)置,不懂英文也不要怕,可以把軟件界面語言設(shè)置為簡體中文。官網(wǎng)的站點(diǎn)也有中文的版面。
            5、網(wǎng)站的用戶參與度非常高,用戶可以上傳自己的作品到該網(wǎng)站,可以欣賞其他用戶的作品,看到喜歡的也可以下載下來研究研究,當(dāng)然也可以用到自己的作品中哦。

            Scratch的一些統(tǒng)計(jì)數(shù)據(jù),從其中你就可以看出此軟件有多優(yōu)秀,看過之后是否選擇此編程語言做為自己的入門語言,那就看你的了。
            第一幅圖:scratch網(wǎng)站的訪問者都來自哪些城市
            scratch網(wǎng)站的訪問者都來自哪些城市

            第二幅圖:scratch網(wǎng)站的注冊(cè)用戶年齡分布圖(藍(lán)色代表男性,紅色代表女性)
            scratch網(wǎng)站的注冊(cè)用戶年齡分布圖
            posted @ 2011-10-24 14:54 黃劍父 閱讀(2976) | 評(píng)論 (1)編輯 收藏

            原文地址:http://www.cprogramming.com/whyc.html

            為什么學(xué)習(xí)C

            Why Learn C?

            現(xiàn)在大家在用的計(jì)算機(jī)語言的數(shù)量多得可怕。從高級(jí)語言(比如VB)到低級(jí)語言,有非常多的選擇(Perl,Ruby和Python語言,對(duì)于很多任務(wù)的實(shí)現(xiàn)都是不錯(cuò)的選擇)。Java已經(jīng)成為了一些項(xiàng)目非常受歡迎的語言,某種程度上也是因?yàn)樗鼡碛写罅康腁PI和虛擬機(jī)機(jī)制提供了比較好的安全性。(內(nèi)存垃圾收集器也是一個(gè)非常不錯(cuò)的功能,可以使得程序員更有效率。)
            There are an awful lot of programming languages available right now -- everything from the extremely high level (such as Visual Basic) to the low level power of assembly, and a good variety of specialized options in between (Perl, Ruby, and Python are good choices for many tasks). Java has also become quite the hot programming language for some tasks, in part because of its large API and in part because the virtual machine provides some elements of security. (Garbage collection is another nice feature and can make programmers much more efficient.)
            然而,學(xué)習(xí)c語言編程,也有很多很好的理由。第一,歷史悠久:C語言已有30多年的歷史了(譯者注:到現(xiàn)在已有近40年了),能找到大量的有效的源代碼。這也意味著有很多可以學(xué)習(xí)的例子,也有很多是可以直接拿來用的代碼。而且,語言的很多問題都已經(jīng)說明的很清楚--它可以更好的理解,并且你可以找到很多很不錯(cuò)的教程。另外,對(duì)于C,你可以獲得很多你能理解的看法和見解。
            Nevertheless, there are some good reasons to learn to program in C. First, age has its advantages: C has been around for 30 years, and there is a ton of source code available. This means there's a lot to learn from, and a lot to use. Moreover, many of the issues with the language have been clearly elucidated -- it's well understood, and you can find a lot of tutorials available. Plus, with C, you get lots of strong opinions mixed with insights that you can understand.

            由于歷史的原因,C做為Unix的一個(gè)系統(tǒng)編程語言,C已經(jīng)成為了一門通用的編程語言。有時(shí)候用C語言來表達(dá)一些編程上的想法,大部分人都會(huì)感覺到比較舒服。
            As a result of its age and its use as the language of system programming for Unix, C has become something of the lingua franca of programming. C is a great language for expressing common ideas in programming in a way that most people are comfortable with. Moreover, a lot of the principles used in C -- for instance, argc and argv for command line parameters, as well as loop constructs and variable types -- will show up in a lot of other languages you learn so you'll be able to talk to people even if they don't know C in a way that's common to both of you.

            第三,C是比較接近機(jī)器語言。
            Third, C is reasonably close to the machine. When you're working with pointers, bytes, and individual bits, things like optimization techniques start to make a lot more sense. There's also utility in knowing exactly how something works underneath the hood -- this helps a great deal when something you're trying to do in a higher level language seems way slower than expected, or just doesn't work at all. You also tend to get a better picture of advanced topics like exactly how networking works. A higher level language will make it a little bit simpler, but it'll be harder to understand what's going on, and when things stop working, it's much better to know exactly what's going on so you can fix it. Additionally, if you like computer science as a discipline, or just like knowing how things work learning the details of the system is great fun.

            實(shí)際上,很多有趣的編程都可以用C來做--比如,系統(tǒng)軟件和數(shù)據(jù)管理系統(tǒng)(Berkeley DB)。如果你想寫一個(gè)比較復(fù)雜的web程序,C也是一個(gè)很不錯(cuò)的選擇。如果你想寫一個(gè)非常好的,快的,C也是很好的選擇。你可以用C來寫整個(gè)操作系統(tǒng),想用Java來做這個(gè)事情是非常難的,對(duì)于腳本語言來說是幾乎不可能的。而且C是一門非常簡潔精煉的語言,它使得非常有趣的編程看起來更優(yōu)雅,你的編程之旅將會(huì)有一個(gè)很好的開始。
            In fact, a lot of fun programming is done in C -- for instance, system software and data managers such as Berkeley DB. If you want to be able to do more than write a simple web app, C is a great language. If you want to write a great, fast game, C is again a great choice. You can write an entire OS in C. It'll be much harder to do so in Java, and nearly impossible in a scripting language. And the language, being succinct as C is, will probably make your fun program more elegant looking to boot.


            我對(duì)于這篇文章所談的話題,想補(bǔ)充幾點(diǎn)。
            1、學(xué)好C,可以幫助理解其他語言中的一些概念。
            比如Java中的引用的概念,如果理解了C語言中的指針的概念,就能很好的理解“引用”這個(gè)概念了,而不理解指針的概念想把引用的概念理解的很透徹,是比較難的。

            2、學(xué)會(huì)了C語言,再學(xué)習(xí)其他語言會(huì)感覺到更輕松。
            Object-C,Java,C++等等很多高級(jí)語言的語法都與C是相似的。學(xué)會(huì)了C后,基本上只要花上一周的時(shí)間了解一下其他語言的特性,就基本上可以看懂其他語言的源代碼了。

            3、從現(xiàn)實(shí)角度來考慮,學(xué)好C,找到一份好工作的可能性也是大大增強(qiáng),特別是對(duì)于剛畢業(yè)的大學(xué)生,或工作經(jīng)驗(yàn)比較少的程序員。現(xiàn)在需要有C語言基礎(chǔ),擅長于C語言的,工作崗位也是比較多。比如拿現(xiàn)在非常流行的iPhone,iPad等設(shè)備的應(yīng)用程序,開發(fā)語言就是Objective-C語言。Objective-C是蘋果Mac OS X、iOS平臺(tái)的開發(fā)語言,Objective-C是基于C語言的,增加面向?qū)ο蟮南嚓P(guān)特性。你可以認(rèn)為Objective-C就是另一個(gè)版本的C++,也就是采用了與C++不同的語法,但也實(shí)現(xiàn)了面向?qū)ο蟆D阌辛薈語言的基礎(chǔ),再學(xué)Objective,難度就不大了。
            你可以到那些招聘網(wǎng)站去看看,查查iPhone相關(guān)的開發(fā)工程師的要求,是不是很多都要求有C/C++的基礎(chǔ)和經(jīng)驗(yàn)。
            還有一些系統(tǒng)開發(fā)和底層比較相關(guān)的,很多都是需要用C語言開發(fā)的。拿信息安全行業(yè)來講,很多安全產(chǎn)品都是用C語言來開發(fā)的。還有游戲行業(yè)很多都是用C或C++。

            還有一點(diǎn),很多初學(xué)者認(rèn)為學(xué)習(xí)C很難。其實(shí)我想說的是難并不是計(jì)算機(jī)語言的問題,難的是因?yàn)槟阌糜?jì)算機(jī)解問題的思維還沒建立起來。因?yàn)槟氵M(jìn)入的是一個(gè)新的領(lǐng)域,以前沒有接觸過計(jì)算機(jī)編程,對(duì)于怎么用計(jì)算機(jī)來解決現(xiàn)實(shí)中的問題的這種思維你還沒有建立起來,畢竟用計(jì)算機(jī)解題的思維,和用數(shù)學(xué)解題的思維還是有些不一樣的,所以你會(huì)覺得學(xué)習(xí)C語言很難。
            如果你在學(xué)習(xí)C語言的同時(shí),再進(jìn)行一些程序員的思維訓(xùn)練,我覺得情況就會(huì)大有改善。
            posted @ 2011-10-20 17:07 黃劍父 閱讀(2618) | 評(píng)論 (1)編輯 收藏
            Over the past decade-and-a-half of teaching introductory computer programming I have noticed increasingly that students have difficulty with solving problems. It is common to see learners read a programming problem description  and immediately try to write the programming language source code (usually whilst sitting at a PC typing straight into the editing window of the compiler environment). When they ask for help it is often the case that their difficulty lies not with manipulating the programming language syntax (C, Pascal, Java, or whatever) but in understanding what it is they're trying to solve. In fact, many times they confuse their syntax-handling difficulties with their problem-solving difficulties and blame their frustration on programming itself or on the chosen programming language. Some of them then become so downhearted that they decide they cannot do computer programming and transfer to a course that doesn't require them to study it.

            這個(gè)話題挺有意思,我看了他的練習(xí)題,還真不錯(cuò),有時(shí)候覺得。算法和計(jì)算機(jī)的語言的學(xué)習(xí)應(yīng)該是有另外一種方式。
            換句話說,在深入學(xué)習(xí)語言和算法,可以先來一碟開胃菜。
            網(wǎng)站地址:
            http://www.howtothinklikeaprogrammer.com/forum/index.php
            書名是:《How to Think Like a Programmer: Program Design Solutions for the Bewildered》By Paul Vickers。
            posted @ 2011-10-19 23:03 黃劍父 閱讀(1985) | 評(píng)論 (0)編輯 收藏
            原文:http://www.cprogramming.com/tutorial/thinking.html
            很多人通過Email問我,怎樣開始寫一個(gè)程序。也許最好的建議非常簡單,把程序的步驟寫下來:一旦你開始把想法或者代碼寫下來后,你就會(huì)對(duì)你的項(xiàng)目有一些感覺了。通常程序設(shè)計(jì)有兩種通用的做法:從上到下的方式和從下到上的方式。
            A lot of people email me asking the way to start some program or another. Perhaps the best advice is simply to start writing down a layout for the program: once you start writing down ideas or code you'll start to get a feel for your project. There are two standard methods of program design: the top-down approach and the bottom-up approach. Top-down programming involves writing code that calls functions you haven't defined and working through the general algorithm before writing the functions that do the processing. Top-down programming is, to a good degree, a very abstract way of writing code because it starts out by using functions you haven't designed, and that you perhaps do not know how to design. The bottom-up approach to programming is the opposite: the programmer writes the basic functions she realizes will be necessary at some point in the programming and then work up to the more complex parts of the program.

            比較有意思的是,那兩種方法都是關(guān)注程序中要執(zhí)行的動(dòng)作或方法,而不是關(guān)注程序要處理的數(shù)據(jù)。很多時(shí)候,寫程序最好的方法是,寫出你將要用到或處理的數(shù)據(jù),然后再從上到下的想怎么樣去處理這些數(shù)據(jù),最后才能得到你需要的結(jié)果。首先定義數(shù)據(jù),然后再寫出那些要處理這些數(shù)據(jù)的相關(guān)的函數(shù)。,這樣你才會(huì)得到你的程序應(yīng)該怎樣寫的基本思路,
            It's interesting that both of these approaches focus on the actions of the program rather than the objects the program manipulates - variables. Many times, the best way to write a program is to figure out the variables you need to work with and then progress with a top-down approach to the program that manipulates those variables. By defining variables first and then working with functions that work on them, you will always maintain a basic foundation of what your program should be doing. Once you have an idea of what variables you will be using, then you can write functions to perform the operations you need to perform on the variables while maintaining sight of the goal. Finally you can write the code for each individual function.

            Another value to defining variables before writing code is that many times you can accomplish an entire program without many functions; this fact is especially true when you are a beginner making simple programs. The variables give you the raw materials you need to begin working with the tools: loops, if statements, library functions, and perhaps user defined functions.


            現(xiàn)在讓我們來看一個(gè)關(guān)于怎樣開始寫一個(gè)完整程序的例子。假設(shè)你要寫的程序是要模擬一個(gè)DVD商店的租售系統(tǒng),這個(gè)系統(tǒng)需要計(jì)算出出租DVD的總收入。你的程序有可能要求,需要輸入一個(gè)代碼,告訴你這個(gè)DVD租售的價(jià)格是2元一天還是是3元一天,然后還需要它出租了多少天,最后如果這個(gè)輸入的代碼是0,整個(gè)程序就結(jié)束了。你應(yīng)該要分別計(jì)算出租金為3元/天和2元/天的DVD的出租的總天數(shù)。拿這個(gè)程序來說,思考設(shè)計(jì)程序的最好的方式是,想象為了計(jì)算出租金的收入,你需要存儲(chǔ)哪些信息:

             

            • 你需要一個(gè)變量用來存儲(chǔ)總收入,當(dāng)程序結(jié)束時(shí);
            • 你需要一個(gè)臨時(shí)變量用來存儲(chǔ)代表DVD的租金的代號(hào);
            • 你需要一個(gè)臨時(shí)變量用來存儲(chǔ)某個(gè)DVD出租的天數(shù);
            • 你需要一個(gè)變量來存儲(chǔ)租金為3元/天的所有DVD出租了多少天的總數(shù);
            • 最后,你還需要一個(gè)變量來存儲(chǔ)租金為2元/天的所有DVD出租了多少天的總數(shù);

             

            Let's take a look at an example of how to go about thinking about a program. If you were to write a program to simulate a video store rental system that calculates the gross revenue from rentals, you might be asked to write a program that accepts a code telling you whether a certain video was rented at $2.00 (input as 2) a day or $3.00 (input as 3) a day and then asks for how many days it was rented out for; finally, if the code for the cost of rental is 0 the program should terminate. You should also count the number of days videos were rented at $3.00 per day and $2.00 per day. The best way to think about the design for a program such as this one is to imagine what information you need to store in order to calculate the revenue:

            • you need a variable to store the total dollar amount at the end of the program;
            • you need a temporary variable to store the code for the cost of a transaction;
            • you need a temporary variable to store the number of days a specific video was rented;
            • you need a variable to store the number of days each video was rented;
            • you need a variable to count the total number of days $3.00 videos were rented;
            • finally, you need a variable to count the total number of days $2.00 videos were rented.

            一旦你認(rèn)識(shí)到你需要這些數(shù)據(jù),那么你就很容易想出如何處理這些數(shù)據(jù):比如,你知道租金2元/天的DVD的總收入=所有租金為2元/天DVD的出租天數(shù)之和*2;類似的也可以計(jì)算出租金3元/天的DVD的總收入。你也會(huì)理解這個(gè)“代表DVD的租金的代號(hào)”,這個(gè)變量的用處是,當(dāng)用戶輸入某個(gè)DVD出租的天數(shù)時(shí),決定哪個(gè)變量會(huì)被操作。在你的程序中你需要一個(gè)循環(huán)結(jié)構(gòu)。


            Once you realize you need these variables, you can easily imagine how to translate them in terms of each other: for example, you know the total amount of revenue is the number of days videos at $2.00 were rented times $2.00; in similar fashion, you know the relationship for $3.00 a day videos. You should understand that the transaction 'code' determines which variables are manipulated when the user inputs the number of days a specific video was rented (for example, whether to add to the count of days for $2.00 videos or $3.00 videos). You'll probably need a loop in your program (although you can't necessarily infer this from the variables).

             

            程序的代碼有可能會(huì)像下面那樣:

            The code might look as follows:

             1 
             3 int main()
             4 {
             5   int total_dollars = 0;
             6   int total_days_at_3_dollars = 0;
             7   int total_days_at_2_dollars = 0;
             8   int transaction_code = 0;
             9   int days_for_one_video = 0;
            10   do
            11   {
            12     if(transaction_code==2)
            13       total_days_at_2_dollars+=days_for_one_video;
            14     if(transaction_code==3)
            15       total_days_at_3_dollars+=days_for_one_video;
            16     cout<<"Please enter a transaction code and number of days a video was rented: ";
            17     cin>>transaction_code>>days_for_one_video;
            18   }while(transaction_code!=0)
            19   return 0
            20 }

            我希望,你現(xiàn)在已經(jīng)有了一個(gè)基本的思路,在寫代碼之前,應(yīng)該如何安排你的程序的結(jié)構(gòu)。

            Hopefully, you now have a basic idea of how to lay out your program structure in your mind before you begin to write code.

             

            posted @ 2011-10-19 11:00 黃劍父 閱讀(1886) | 評(píng)論 (0)編輯 收藏

            application文件夾為ext js4的應(yīng)用程序目錄,
            ext文件夾為ext js 4資源的目錄,
            其他文件或文件夾則為yii框架所涉及到的。
            posted @ 2011-07-27 14:50 黃劍父 閱讀(2089) | 評(píng)論 (1)編輯 收藏
            Apache服務(wù)器下yii的urlManager設(shè)置
            step1:Yii的配置文件config/main.php中
            'components'下增加
             1 'urlManager'=>array(
             2     'urlFormat'=>'path',
             3     'showScriptName' => false,
             4     'rules'=>array(
             5         'urls.js' => 'workspace/urls',
             6         'env.js' => 'workspace/env',
             7                 '<controller:\w+>/<id:\d+>'=>'<controller>/view',
             8                 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
             9                 '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            10             ),
            11         ),
            step2:開啟Apache的配置文件httpd.conf中LoadModule rewrite_module modules/mod_rewrite.so和AllowOverride屬性設(shè)置為All
            step3:編寫一個(gè).htaccess文件放在app的根目錄,添加以下幾行到文件中
            Options +FollowSymLinks
            IndexIgnore */*
            RewriteEngine on

            # if a directory or a file exists, use it directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d

            # otherwise forward it to index.php
            RewriteRule . index.php
            posted @ 2011-07-26 14:20 黃劍父 閱讀(5316) | 評(píng)論 (0)編輯 收藏
            網(wǎng)站:
            http://www.sencha.com/products/extjs/
            posted @ 2011-07-18 11:03 黃劍父 閱讀(270) | 評(píng)論 (0)編輯 收藏

            printf的格式控制的完整格式:
            %  -  0  m.n  l或h  格式字符
            下面對(duì)組成格式說明的各項(xiàng)加以說明:
            ①%:表示格式說明的起始符號(hào),不可缺少。
            ②-:有-表示左對(duì)齊輸出,如省略表示右對(duì)齊輸出。
            ③0:有0表示指定空位填0,如省略表示指定空位不填。
            ④m.n:m指域?qū)挘磳?duì)應(yīng)的輸出項(xiàng)在輸出設(shè)備上所占的字符數(shù)。N指精度。用于說明輸出的實(shí)型數(shù)的小數(shù)位數(shù)。為指定n時(shí),隱含的精度為n=6位。
            ⑤l或h:l對(duì)整型指long型,對(duì)實(shí)型指double型。h用于將整型的格式字符修正為short型。

            ---------------------------------------
            格式字符
            格式字符用以指定輸出項(xiàng)的數(shù)據(jù)類型和輸出格式。
             ①d格式:用來輸出十進(jìn)制整數(shù)。有以下幾種用法:
            %d:按整型數(shù)據(jù)的實(shí)際長度輸出。
            %md:m為指定的輸出字段的寬度。如果數(shù)據(jù)的位數(shù)小于m,則左端補(bǔ)以空格,若大于m,則按實(shí)際位數(shù)輸出。
            %ld:輸出長整型數(shù)據(jù)。
            ②o格式:以無符號(hào)八進(jìn)制形式輸出整數(shù)。對(duì)長整型可以用"%lo"格式輸出。同樣也可以指定字段寬度用“%mo”格式輸出。
            例:
               main()
               { int a = -1;
                 printf("%d, %o", a, a);
               }
              運(yùn)行結(jié)果:-1,177777
              程序解析:-1在內(nèi)存單元中(以補(bǔ)碼形式存放)為(1111111111111111)2,轉(zhuǎn)換為八進(jìn)制數(shù)為(177777)8。
            ③x格式:以無符號(hào)十六進(jìn)制形式輸出整數(shù)。對(duì)長整型可以用"%lx"格式輸出。同樣也可以指定字段寬度用"%mx"格式輸出。
            ④u格式:以無符號(hào)十進(jìn)制形式輸出整數(shù)。對(duì)長整型可以用"%lu"格式輸出。同樣也可以指定字段寬度用“%mu”格式輸出。
            ⑤c格式:輸出一個(gè)字符。
            ⑥s格式:用來輸出一個(gè)串。有幾中用法
            %s:例如:printf("%s", "CHINA")輸出"CHINA"字符串(不包括雙引號(hào))。
            %ms:輸出的字符串占m列,如字符串本身長度大于m,則突破獲m的限制,將字符串全部輸出。若串長小于m,則左補(bǔ)空格。
            %-ms:如果串長小于m,則在m列范圍內(nèi),字符串向左靠,右補(bǔ)空格。
            %m.ns:輸出占m列,但只取字符串中左端n個(gè)字符。這n個(gè)字符輸出在m列的右側(cè),左補(bǔ)空格。
            %-m.ns:其中m、n含義同上,n個(gè)字符輸出在m列范圍的左側(cè),右補(bǔ)空格。如果n>m,則自動(dòng)取n值,即保證n個(gè)字符正常輸出。
            ⑦f格式:用來輸出實(shí)數(shù)(包括單、雙精度),以小數(shù)形式輸出。有以下幾種用法:
            %f:不指定寬度,整數(shù)部分全部輸出并輸出6位小數(shù)。
            %m.nf:輸出共占m列,其中有n位小數(shù),如數(shù)值寬度小于m左端補(bǔ)空格。 
            %-m.nf:輸出共占n列,其中有n位小數(shù),如數(shù)值寬度小于m右端補(bǔ)空格。
            ⑧e格式:以指數(shù)形式輸出實(shí)數(shù)。可用以下形式:
            %e:數(shù)字部分(又稱尾數(shù))輸出6位小數(shù),指數(shù)部分占5位或4位。
            %m.ne和%-m.ne:m、n和”-”字符含義與前相同。此處n指數(shù)據(jù)的數(shù)字部分的小數(shù)位數(shù),m表示整個(gè)輸出數(shù)據(jù)所占的寬度。
            ⑨g格式:自動(dòng)選f格式或e格式中較短的一種輸出,且不輸出無意義的零。

            ---------------------------------------
            關(guān)于printf函數(shù)的進(jìn)一步說明:
            如果想輸出字符"%",則應(yīng)該在“格式控制”字符串中用連續(xù)兩個(gè)%表示,如:
            printf("%f%%", 1.0/3);
            輸出0.333333%。

            ---------------------------------------
            對(duì)于單精度數(shù),使用%f格式符輸出時(shí),僅前7位是有效數(shù)字,小數(shù)6位.
            對(duì)于雙精度數(shù),使用%lf格式符輸出時(shí),前16位是有效數(shù)字,小數(shù)6位.

            ######################################拾遺########################################
            由高手指點(diǎn)
            對(duì)于m.n的格式還可以用如下方法表示(例)
            char ch[20];
            printf("%*.*s\n",m,n,ch);
            前邊的*定義的是總的寬度,后邊的定義的是輸出的個(gè)數(shù)。分別對(duì)應(yīng)外面的參數(shù)m和n 。我想這種方法的好處是可以在語句之外對(duì)參數(shù)m和n賦值,從而控制輸出格式。


            今天(06.6.9)又看到一種輸出格式 %n 可以將所輸出字符串的長度值賦紿一個(gè)變量, 見下例:

            int slen;

            printf("hello world%n", &slen);

            執(zhí)行后變量被賦值為11。

            又查了一下, 看到一篇文章(查看)說這種格式輸出已經(jīng)確認(rèn)為一個(gè)安全隱患,并且已禁用。再搜搜果然這種用法都被用來搞什么溢出、漏洞之類的,隨便找了一個(gè):格式化字符串攻擊筆記。
            posted @ 2011-04-26 16:18 黃劍父 閱讀(300) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題  下一頁
            久久精品aⅴ无码中文字字幕不卡| 国产午夜免费高清久久影院| 天天影视色香欲综合久久| 国产欧美久久久精品影院| 久久伊人五月丁香狠狠色| 成人久久精品一区二区三区| 久久精品国产精品亚洲| 久久久无码精品亚洲日韩京东传媒| 看久久久久久a级毛片| 国产成人AV综合久久| 亚洲精品tv久久久久久久久 | 伊人色综合九久久天天蜜桃| 99精品久久久久久久婷婷| 久久亚洲国产欧洲精品一| 99久久免费国产精品特黄| 青青青青久久精品国产h| 精品多毛少妇人妻AV免费久久| 久久综合久久综合久久| 久久99久国产麻精品66| 久久99精品久久久久久齐齐| 日韩精品久久久久久久电影蜜臀| 久久精品无码一区二区三区免费 | 91精品国产91久久久久久青草| 久久免费看黄a级毛片| 久久精品国产72国产精福利| 国产精品99久久久久久人| 久久午夜伦鲁片免费无码| 久久国产AVJUST麻豆| 久久影视综合亚洲| 精品国产婷婷久久久| 青草影院天堂男人久久| AV无码久久久久不卡蜜桃| 久久综合狠狠综合久久综合88 | 久久精品中文字幕第23页| 久久精品国产91久久综合麻豆自制 | 久久久久久九九99精品| 久久午夜羞羞影院免费观看| 久久精品国产男包| 久久亚洲精品无码VA大香大香| 香蕉久久AⅤ一区二区三区| 久久亚洲精品无码观看不卡|