这是来自unix/linux编程实践教程上的例子。
除了linux的系统调用,值得注意的是还有一些细节问题。
比如对于fgets()函数接受的字符串的处理。
char *fgets(char *s, int size, FILE *stream);
fgets() reads in at most one less than size characters from stream and
stores them into the buffer pointed to by s. Reading stops after an
EOF or a newline. If a newline is read, it is stored into the buffer.
A '/0' is stored after the last character in the buffer.
fgets 函数,从数据流读取比size少1个字符,把他们存储到s指向的缓冲区。如果遇到EOF或者换行,则
停止。如果是换行符,换行符也被存储在缓冲区。'/0'被存储在缓冲区的末尾.
所以在过程中要去掉击键产生的'/n',通过makestring(char *buf)函数。