首页 > 技术文章 > 最近想要正式写点小软件赚外快了.所以认真对待每一次编码。

MyloverisU 2014-04-04 14:59 原文

http://www.cnblogs.com/vimsk/archive/2010/12/11/1901698.html

《The Cert C Secure Coding Standard》 作者:(美)塞克德(Robert C. Seacord)
中文译本:《C安全编码标准》 徐波 等译 机械工业出版社

  以前一些偷懒的想法就不能要了,严格加强错误判断,防止程序异常,多写文字说明,增强互动。而且还要变得有耐心!

  今天思瀚又问我一道作业,虽然很费时间,又是义务的,耐心……

  不考任何算法。。

作业如下:

A naturalist is off to explore the amazon jungle, and needs a computer program to record information about all the new species discovered. For each new species it is necessary to store the name (max 128 characters), size (a real number), and the type of animal (an enum type, one of mammal, insect, bird, or fish). Write a program to store and print out the information. (5.0%)

An array of structures must be used, so that each new species can be recorded in an element of the array. It's not known in advance how many new species will be found, so the program must malloc for an initial array of size 1, and use the doubling realloc technique (as discussed in class) to get more memory as required. You must always check the return value from malloc, as done in the Malloc wrapper function (or just use Malloc :-). Here what a sample run should look like (with the keyboard input shown in italics) ...

> NewSpecies
Enter animal information ("exit" to exit)
What is the name : bloatfish
What is the size : 12.47
What is the type : fish
Enter animal information ("exit" to exit)
What is the name : stingybeasty
What is the size : 0.13
What is the type : insect
Enter animal information ("exit" to exit)
What is the name : toothfulsloth
What is the size : 33.33
What is the type : mammal
Enter animal information ("exit" to exit)
What is the name : exit

The following new species were found:
bloatfish            has size  12.47 and is a fish
stingybeasty         has size   0.13 and is a insect
toothfulsloth        has size  33.33 and is a mammal 

   要考虑安全性。scanf,printfVS2010不建议用,它给出了警告……但是只能在windows上使用吧..

  每一次输错的处理,比如浮点数输入非法……内存不够用了怎么办?每一次需要重新补录数据吗?应该把数据存到本地硬盘中,这样的话最好需要一个界面。 type能否简化输入,每一次需要输全名太麻烦了,可以选择下拉条,可以增加type种类。新物种重名处理。数据管理界面。可以放图片,写comments。如果是野外的话得增加GPS导航功能。增加日志功能。可以把日志发布到blog上。物种管理:管理名称,大小,种类,时间地点,备注,照片(还有什么?),如果这样的话需要和业内通用格式相匹配,这样导入导出也很方便。所以需要查通用的物种数据是如何存放的。应该使用数据库……

  暂时想到这么多,如果真正做的话,应该有很大的空间改进。

推荐阅读