??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久久午夜成人影院,人人狠狠综合久久88成人,久久久久久国产精品无码超碰http://www.shnenglu.com/deercoder/<P><FONT style="FONT-SIZE: 20px" color=#ff0000>U篏Q坚持!</FONT></P> <P><FONT style="FONT-SIZE: 20px" color=#ff0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ---------我是一只IT小?lt;/FONT></P>zh-cnTue, 06 May 2025 20:03:44 GMTTue, 06 May 2025 20:03:44 GMT60此博客停止更?/title><link>http://www.shnenglu.com/deercoder/archive/2014/12/14/209182.html</link><dc:creator>deercoder</dc:creator><author>deercoder</author><pubDate>Sun, 14 Dec 2014 05:56:00 GMT</pubDate><guid>http://www.shnenglu.com/deercoder/archive/2014/12/14/209182.html</guid><wfw:comment>http://www.shnenglu.com/deercoder/comments/209182.html</wfw:comment><comments>http://www.shnenglu.com/deercoder/archive/2014/12/14/209182.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/deercoder/comments/commentRss/209182.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/deercoder/services/trackbacks/209182.html</trackback:ping><description><![CDATA[一直以来,此博客都是本人用于记录学习心得和技术笔记的一个地方,大学的时候开始笔耕不辍,留下了自׃宝늚回忆Q也记录自己的青春。工作后Q由于工作内容的限制Q技术分享很,而且个h亦疏于管理,所以已成荒废趋ѝ?br /><br />目前Q本人在帝求学Q专研大数据和深度学习,Ud互联|及应用Q考虑到研I和个h提升的需要开通了Google website和google blogger用于写作Q以历练p。本Z直崇互联网分n和开源Y件精,亦准备后l在自己的能力范围内Z联网普及和开源Y件的开发和推广做A献,考虑到目前此博客已不再适合自己的写作,故{战其他地址Q望各位看客见谅?br /><br />另外Q希望看客不要再留下Mnd的评论,于h于己都无益处Q本人写作纵使漏z百Z非强q你领会接受Q只作ؓ个h存使用而已Q一个对技术有热爱的h应该是有探究_来判断正误,而非拿来M或者动辄破口大骂,我也没有旉L理这些难{大雅之堂的评论Q望理解见谅?br /><br />Dec 14th, 12:54 am @MA<img src ="http://www.shnenglu.com/deercoder/aggbug/209182.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/deercoder/" target="_blank">deercoder</a> 2014-12-14 13:56 <a href="http://www.shnenglu.com/deercoder/archive/2014/12/14/209182.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Adboe Reader提示中文字体有问?/title><link>http://www.shnenglu.com/deercoder/archive/2013/03/10/198330.html</link><dc:creator>deercoder</dc:creator><author>deercoder</author><pubDate>Sun, 10 Mar 2013 04:30:00 GMT</pubDate><guid>http://www.shnenglu.com/deercoder/archive/2013/03/10/198330.html</guid><wfw:comment>http://www.shnenglu.com/deercoder/comments/198330.html</wfw:comment><comments>http://www.shnenglu.com/deercoder/archive/2013/03/10/198330.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/deercoder/comments/commentRss/198330.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/deercoder/services/trackbacks/198330.html</trackback:ping><description><![CDATA[<h1>Adobe Reader提示中文字体~失</h1> <p>正常使用情况下,没有M问题Q环境是Q?/p> <p>OS: Ubuntu 10.04</p> <p>Version: Aodbe Reader 9.5.1</p> <p>但是打开部分文档Q可能是LateX生成的文档时Q出现问题,׃字体不完全导致?/p> <p>解决办法Q?/p> <p>下蝲Q?/p> <pre><code> http://ardownload.adobe.com/pub/adobe/reader/unix/9.x/9.1/misc/FontPack910_chs_i486-linux.tar.bz2 </code></pre> <p>然后以管理员w䆾q行Q即可?/p> <p><strong> 此安装包解决了字体的问题Q不仅仅针对?Adobe Reader软gQ用默认的阅读器会发现也能够正常浏览文了Q所以对于字体是普遍生效的?/strong></p> <img src ="http://www.shnenglu.com/deercoder/aggbug/198330.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/deercoder/" target="_blank">deercoder</a> 2013-03-10 12:30 <a href="http://www.shnenglu.com/deercoder/archive/2013/03/10/198330.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python字符串换行处?/title><link>http://www.shnenglu.com/deercoder/archive/2012/07/08/182137.html</link><dc:creator>deercoder</dc:creator><author>deercoder</author><pubDate>Sat, 07 Jul 2012 16:52:00 GMT</pubDate><guid>http://www.shnenglu.com/deercoder/archive/2012/07/08/182137.html</guid><wfw:comment>http://www.shnenglu.com/deercoder/comments/182137.html</wfw:comment><comments>http://www.shnenglu.com/deercoder/archive/2012/07/08/182137.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/deercoder/comments/commentRss/182137.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/deercoder/services/trackbacks/182137.html</trackback:ping><description><![CDATA[最q看了一点点Python的东西,感觉q门语言非常强大Q已l到了o人发指的E度Q结果是Q想要实现的很多功能都可以用极ؓ单的几句代码实现Q难怪这么语aq么有生命力。至于说它让人变的更W,让hq底层处理Q忽视了基本的硬件了解这U指责,或者说它让E序员的工作和生zL加便利等争论Q我也没有多大的兴趣M解,语言只是工具Qؓ我所用而已?br /><br />虽然了解不多Q不q感觉处理文件和字符串非常强大,因此有一个需求,希望网上copy的连l的单词l成的字W串按照I格分割开来,q新写入到文g中,q样文g的每一行都是一个单词,而且后面q可以加入注释。由于手动换行非帔R烦,所以希望用python来实现这个简单的功能?br />具体实现代码如下Q确实非常简单:<br /><div id="9fd3tlf" class="vimiumReset vimiumHUD" style="right: 150px; opacity: 0; display: none; "></div><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">#</span><span style="color: #008000; ">! /usr/bin/python</span><span style="color: #008000; "><br />#</span><span style="color: #008000; ">Description: read file and arrange them in lines by words</span><span style="color: #008000; "><br /></span><br />file = open(<span style="color: #800000; ">"</span><span style="color: #800000; ">test</span><span style="color: #800000; ">"</span>, <span style="color: #800000; ">"</span><span style="color: #800000; ">r</span><span style="color: #800000; ">"</span>)<br />str = file.read()<br />tup = str.split(<span style="color: #800000; ">"</span><span style="color: #800000; "> </span><span style="color: #800000; ">"</span>)<br />writeStr = <span style="color: #800000; ">""</span><br /><span style="color: #0000FF; ">for</span> i <span style="color: #0000FF; ">in</span> tup:<br />    writeStr += i + <span style="color: #800000; ">"</span><span style="color: #800000; ">\n</span><span style="color: #800000; ">"</span><br />outfile = open(<span style="color: #800000; ">"</span><span style="color: #800000; ">out</span><span style="color: #800000; ">"</span>, <span style="color: #800000; ">"</span><span style="color: #800000; ">w</span><span style="color: #800000; ">"</span>)<br />outfile.write(writeStr)<br /><span style="color: #0000FF; ">print</span> tup</div><br />实非常单,最后也实现了想要的效果。后l需要想办法加入查询的过哦你你,卛_每一行的q个单词Q想办法查询它的意思,然后一起写q去Q这Pcopy的这个连串的字符串就能够得到每一个单词的释义了?br /><br />另外QVIM有一个很好的功能Q用JQ在命o模式下可以连接成一行,因此文g开始的时候是Q?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"> ### filename: out<br />impart<br />apotheosis<br />pulp<br />nobility<br />reimburse<br />flora<br />deliberately<br />twine<br />heresy<br />effluent<br />condone<br />flout<br />sermon<br />concur<br />elation<br />slab<br />aerate<br />backdrop<br />emblem<br />chicanery<br />disqualify<br />hypersensitive<br />fitful<br />coil<br />irresolute<br />contemptible<br />hinge<br />tectonics<br />bicker<br />tilted<br />collaborate<br />salutary<br />annul<br />vex<br />maxim<br />scanty<br />reptile<br />transfix<br />impending<br />intersect<br />drill<br />inviting<br />retreat<br />serrated</div><br />l过VIM处理之后变成了一行:<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->### filename: test ####<br />impart apotheosis pulp nobility reimburse flora deliberately twine heresy effluent condone flout sermon concur elation slab aerate backdrop emblem chicanery disqualify hypersensitive fitful coil irresolute contemptible hinge tectonics bicker tilted collaborate salutary annul vex maxim scanty reptile transfix impending intersect drill inviting retreat serrated</div><br />然后在把q个文g作ؓ输入Q经q程序重新写回去Q就成ؓ了第一个上面所C的单词Q现在在思考哪些地方可以抓取这些单词呢Q貌似Google译已经没有API支持了,不知道哪位大侠可以给于指|<img src ="http://www.shnenglu.com/deercoder/aggbug/182137.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/deercoder/" target="_blank">deercoder</a> 2012-07-08 00:52 <a href="http://www.shnenglu.com/deercoder/archive/2012/07/08/182137.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何转换^M行末W号http://www.shnenglu.com/deercoder/archive/2012/07/07/182123.htmldeercoderdeercoderSat, 07 Jul 2012 14:54:00 GMThttp://www.shnenglu.com/deercoder/archive/2012/07/07/182123.htmlhttp://www.shnenglu.com/deercoder/comments/182123.htmlhttp://www.shnenglu.com/deercoder/archive/2012/07/07/182123.html#Feedback0http://www.shnenglu.com/deercoder/comments/commentRss/182123.htmlhttp://www.shnenglu.com/deercoder/services/trackbacks/182123.html因此Q如果在Windows下面~辑的脚本文Ӟ如shell脚本文gQ在Linux下面执行p|Q会提示多一个^MW号Q用VIM打开也会发现增加q个W号?br />
解决办法Q?br />1. 用VIM打开Q设|编码ؓunix
Qset fileformat=unix
然后Q保存,l尾unix格式?br />
2. 使用VIM的替换功能,替换行末的\rW号卛_
:%s/^M//g

3. 使用sed来进行批量处?br /> sed ’s/^M//’ filename > tmp_filename

4. 扚w处理Q推荐用)
sudo apt-get install dos2unix
find . * | xargs dos2unix Q对当前目录下面的所有文件执行{换格式的命oQ?br />
一个需要注意的点:dos2unix需要root权限Q我开始的时候没有用sudoq行Q提C{换失败,后来利用sudo执行卛_?br />问题的根源来源于Q?br />在Windows下面拉取Git上面的代码,l果l版本库所有的文g都加上了行末W号Q而在Linux下面再次~辑该文件就发现所有的问题都出现问题,提交的时候又不能
把所有的文g都提交成Windows的编码,因ؓq部分修Ҏ没有意义的,所以需要批量{换?br />



deercoder 2012-07-07 22:54 发表评论
]]>
斯坦大学开放课E?-~程范式Q四Q?/title><link>http://www.shnenglu.com/deercoder/archive/2012/06/24/180038.html</link><dc:creator>deercoder</dc:creator><author>deercoder</author><pubDate>Sun, 24 Jun 2012 08:57:00 GMT</pubDate><guid>http://www.shnenglu.com/deercoder/archive/2012/06/24/180038.html</guid><wfw:comment>http://www.shnenglu.com/deercoder/comments/180038.html</wfw:comment><comments>http://www.shnenglu.com/deercoder/archive/2012/06/24/180038.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/deercoder/comments/commentRss/180038.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/deercoder/services/trackbacks/180038.html</trackback:ping><description><![CDATA[<p style="margin-top: 18px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style="font-size: x-large; font-weight: 600; "></span></p><p style="margin-top: 18px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style="font-size: x-large; font-weight: 600; ">lD</span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">本节评主要内容是关于泛型数据的拯Q虽然是使用C语言实现Qƈ且没有用到C++中的模板q种泛型~程技术,但是效果却非常好。本节内容紧接上节所的字节位拷贝的知识Q充分利用了字节拯技术?/p> <p style="margin-top: 16px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:x-large; font-weight:600;">W记</span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">׃内容和例子不断深入,实际核心内容则比较集中,因此q里只进行ȝ讨论?/p> <p style="margin-top: 16px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:x-large; font-weight:600;">引例</span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">本节所有的例子都是针对于数据交换来q行的,从最单的例子开始,不断深入?开始是关于一个最单的整数数据的交换实例:</p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">void swap(int a, int b){</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> int tmp = a;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> a = b;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> b = tmp;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">}</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">此例子非常简单,只需要构造一个简单的中间临时变量tmp用来存放a的|q且交换赋值相关的数据Q就可以辑ֈ交换的目的?/p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">但是Q此实例有一个缺P是g递,而不是引用传递,q样Q传递的D然改变,但是只想原始变量的单元却没有改变Q具体来说就是:</p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">a = 23;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">b = 34</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">swap(a, b);</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">执行上面一D语句会发现Q其实aQb的值ƈ没有交换Q原因和C/C++的参数的g递以及指针传递有关系。函数调用的时候,只会拯aQb的|因此调用swap的时候,交换的是形参Q实际参数的值ƈ没有改变?/p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">要实现真正参C递的效果Q需要用指针的Ş式来实现Q?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">void swap(int *vp1, int *vp2) {</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> int a = *vp1;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> *vp1 = *vp2;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> *vp2 = *vp1;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">}</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">再次调用swap(&a, &b)的时候,׃修改掉原来的|因ؓq里传递过ȝ是指针Q所以,?span style=" font-style:italic;">vp1Q?/span>vp2的操?是Ҏ向单元aQb的操作,所以能够修改对应的倹{?/p> <p style="margin-top: 16px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:x-large; font-weight:600;">泛型交换与拷?/span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">上面的例子,只是ҎU特定的cdq行交换Q比如intcdQ如果想对doublecd{进行交换,只需要修改其cd为double卛_Q其他类型类伹{?但是考虑到需要对多种不同cdq行交换Q是否存在一U通用的方法呢Q?在C++中,可以用模板template技术,然而这里,回想起上节课中讲到的字节操作Q能否利用字节的拯来实现呢Q答案是肯定的?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">void swap(void *vp1, void *vp2, int size){</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> char buffer[size];</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> memcpy(buffer, vp1, size);</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> memcpy(vp1, vp2, size);</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> memcpy(vp2, buffer, size);</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">}</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">调用的时候,字号需要给定某个类型,卛_实现。比如,通过Q?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">double a = 23.0, b = 34.0;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">swap(&a, &b, sizeof(double));</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">当然Q对于结构体也可以通过q种形式来进行拷贝?/p> <p style="margin-top: 14px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:large; font-weight:600;">关于上面例子的几点说明:</span></p> <ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style="margin-top: 12px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">q里声明数组的方式,使用的大size是可变的Q这只在某些~译器中支持Q这里只是ؓ了说明字W拷贝的方式Q例子的重点在于交换。当然可以用malloc或者new来动态分配大可变的I间?/li> <li style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">q里使用memcpy(dest, src, size)q个函数来进行内存单元的拯Q注意此函数q不兛_你的数据cdQ单U的q行单元的拷贝而已Q所以虽然编译可能通过Q但是还需要自p行判断和控制?/li> <li style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">q个例子的亮点就在于void*的用,通过它能够实现泛型,即针对于intQshortQcharQstruct{类型都能够保证能够拯交换成功?/li> <li style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">template和这里的区别和优~点。注意到使用模板的话Q编译后Q会为每U类型都生成一U代码,比如int对应的,float对应的,q样如果调用ơ数很多的话Q代码体U会增大Q冗余过多。而这里编译出来就一套代码,更加z?/li> <li style="margin-top: 0px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">q里传递一个参数大size是因为,׃泛型指针void*的存在,所以编译器q不知道要拷贝多个字节Q所以,需要你手动控制q指定一个大?/li></ol> <p style="margin-top: 14px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:large; font-weight:600;">存在的问?/span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">׃~译器会很容易的放过void*带来的错误,所以如果两个类型不同的数据调用此函敎ͼ׃出现问题Q?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> double a = 23.0;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> int b = 345;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> swap(&a, &b, sizeof(double));</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">q里Qdouble和intcd占据的数据空间的大小是不同的Q因此,如果单纯的直接调用这个函敎ͼ׃出错Q简单的l果是Q截断拷贝或者多拯数据?比如Qintcd拯到double数据I间的时候,只有前面2个字节拷贝了Q后面的原来double数据的两个字节仍然保留了Q或者说double拯到int的时候,可能会多拯两个字节到int后面的数据,造成出错。具体的方式Q与后面一个参数sizeof(double)或者sizeof(int)有关pR?/p> <p style="margin-top: 14px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:large; font-weight:600;">初学者容易犯的错?/span></p> <ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">使用void * tmp = vp1Q而不是前面锁讲到的char buffer[size]Q这个错误的原因是由于不理解void不是一个类型,不像intQdouble{属于一个类型,所以错误。void <span style=" font-style:italic;">只能用作函数参数Q返回值才可行。但是可以?void * tmp = (int </span>)&aq类的用法,因ؓ具体的类型即可以赋值给一般的cdQ你只有l定了一个具体的cdQ才能让~译器知道规则,才能~译通过?/li> <li style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">指针的拷贝,何时使用引用地址的问题。一个简单的例子出发Q?/li></ol> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">char * husband = strdup("Fred"); char * wife = strdup("Wilma");</p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">如果想交换两人所指向的空间内容,正确的做法是Q?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">swap(&hustband, &wife, sizeof(char *))</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">也就是说Q这里要交换的是指针的地址Q交换之后,husband的内容发生了变化Q内容变成了原来wife的内容,׃本n是地址Q所以内容变了,实际上所只想的地址也变了,现在husband指向原来wife所指向的地址Q而wife指向原来husband指向的地址?/p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">一个错误的例子是Qswap(husband, wife, &sizeof(char <span style=" font-family:'Courier New,courier';">*</span>))Q这P交换的实际上是他们锁指向的内容,卛_放Fred和Wilama的单元中的内容会交换Q而且Q由于char <span style=" font-family:'Courier New,courier';">*</span>是四个字节,因此交换的就只有四个字节的内宏V?Z会如此呢Q因Z面的例子Q比如要交换aQb单元的内容,传入的就是aQb的地址&a, &bQ同Pq里我直接传入指针,当然交换的是他们指向的单元的内容Q即两个字符丌Ӏ?所以要交换两个指针的内容,p交换他们的地址Q即指针的地址Q指针的指针?/p> <p style="margin-top: 16px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:x-large; font-weight:600;">另外一个例?/span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">思考一个下面线性搜索的例子Q?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">int * lsearch(int key ,int* array, int size){</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> for (int i = 0; i < size; i++) </span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> {</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> if(array[i] == key)</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> return i;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> }</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">}</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">上面的这D代码,直接q回的就是找到烦引的那个下标?/p> <p style="margin-top: 14px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "><span style=" font-size:large; font-weight:600;">利用位比较的方式来实?/span></p> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">同样Qؓ了应用上面我们学到的知识Q这里想要泛型比较,搜烦Q如何实玎ͼ 例如Q对于这里的intQ能否用一个structQ一个double或者其他类型?{案仍然是肯定的Q只不过Q我们需要对其中~译器的工作Q比较的大小q行控制而已?/p> <pre style="margin-top: 12px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">int *lsearch(void *key, void *base, int size, int elementSize){</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> for (int i = 0; i < size; i++) {</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> void * elemeAddr = (char *)base + i * elementSize; </span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> if (memcmp(key, elemeAddr, elementSize) == 0)</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> return elemeAddr;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';"> } </span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" font-family:'Courier New,courier';">}</span></pre> <pre style="margin-top: 0px; margin-bottom: 12px; font-family: 'Courier New,courier'; "></pre> <p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; ">q里的几个说明点是Q首先,传入参数的size是要比较的数组的大,cd我们不知道,qvoid *cdQ然后要传入每一个类型的大小QelementSizeQ这个标C每一个数l成员的大小Q正因ؓ有这个我们才可以_և的定位到具体的单元,利用for循环来比较每一个单元和key的关pR而这里比较用的memcmp来进行,比较的字节数是elementSizeQ传入两个指针即可,而比较的指针是数组的每一个单元的地址Q即elemeAddr而已?br /><br />                                                                                                   ---Written by markdown and HTML file is generated by markdown.</p><p style="margin-top: 12px; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; "></p><img src ="http://www.shnenglu.com/deercoder/aggbug/180038.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/deercoder/" target="_blank">deercoder</a> 2012-06-24 16:57 <a href="http://www.shnenglu.com/deercoder/archive/2012/06/24/180038.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.51uhq.cn" target="_blank">Ʒþþþþ޾Ʒ</a>| <a href="http://www.lishi5.cn" target="_blank">99þۺϾƷ</a>| <a href="http://www.klhome.com.cn" target="_blank">޾ƷƷþ99</a>| <a href="http://www.bjxisaa.cn" target="_blank">ŷþþþþ</a>| <a href="http://www.90key.cn" target="_blank">Ʒþþþaaaa</a>| <a href="http://www.xyszgh.cn" target="_blank">Ʒ˾þ˵Ӱ</a>| <a href="http://www.114best.com.cn" target="_blank">þоƷ</a>| <a href="http://www.yc9z.com.cn" target="_blank">˾þô߽Ʒ</a>| <a href="http://www.hz-yarnexpo.com.cn" target="_blank">޹㽶þþþþ</a>| <a href="http://www.338z.cn" target="_blank">þþƷëƬѹۿ</a>| <a href="http://www.hzust.cn" target="_blank">þþƷһ</a>| <a href="http://www.domino111.com.cn" target="_blank">þþ</a>| <a href="http://www.wtem.cn" target="_blank">˾ƷۺϾþþ</a>| <a href="http://www.job158.cn" target="_blank">ۺ˾þôý</a>| <a href="http://www.uyns.cn" target="_blank">þûƵ</a>| <a href="http://www.anfubbs.cn" target="_blank">þ99Ƶ</a>| <a href="http://www.hunan168.cn" target="_blank">ŷһþۺ</a>| <a href="http://www.delannahotel.com.cn" target="_blank">˾Ʒþһav</a>| <a href="http://www.vcdordvd.cn" target="_blank">ձþþվ</a>| <a href="http://www.blog060422.cn" target="_blank">Ʒþþþþþþþ</a>| <a href="http://www.yes365cc.cn" target="_blank">þþþþ޾Ʒ</a>| <a href="http://www.duopudz.cn" target="_blank">˾þô߽鶹</a>| <a href="http://www.reeway.cn" target="_blank">þۺϾþۺϾþ</a>| <a href="http://www.airesou.cn" target="_blank">avҹһƬѿþ</a>| <a href="http://www.qfzxd.cn" target="_blank">Ʒ˾þþ</a>| <a href="http://www.elecline.com.cn" target="_blank">޹Ʒ˾þ</a>| <a href="http://www.funziot.cn" target="_blank">þþƷҹɫA</a>| <a href="http://www.wd12cjf8.cn" target="_blank">þ66͵Ʒ9</a>| <a href="http://www.wzyuan25.cn" target="_blank">þùŷպƷ</a>| <a href="http://www.hthotel.com.cn" target="_blank">þþþһƷ޹ۺAV </a>| <a href="http://www.qdpin.cn" target="_blank">ŷAŷaþ</a>| <a href="http://www.p7751.cn" target="_blank">ҹƷþӰԺ</a>| <a href="http://www.5icsw.cn" target="_blank">ŷһþþþþþôƬ</a>| <a href="http://www.168zw.cn" target="_blank">ھƷ˾þþþӰԺ԰</a>| <a href="http://www.gfwi.cn" target="_blank">Ʒ18þþ⺾</a>| <a href="http://www.po18h.cn" target="_blank">þþƷaĻؿ</a>| <a href="http://www.trjyzj.cn" target="_blank">þݺҹҹavapp</a>| <a href="http://www.dishengbao.cn" target="_blank">ھƷ˾þþþø</a>| <a href="http://www.sooniy.com.cn" target="_blank">žžƷþþþþ</a>| <a href="http://www.shisanshui.cn" target="_blank">ĻþþƷ</a>| <a href="http://www.tongshi8.cn" target="_blank">ҹavþþþ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>