The C Programming Language
To be continued...
第8章 UNIX系统接口
#include <stdio.h>
#include <fcntl.h>
#include "syscalls.h"
#defien PERMS 0666
void error(char *, ...);
/* cp函数: 将 f1 复制到 f2 */
int main(int argc, char *argv[])
{
int f1, f2, n;
char buf[BUFSIZ];
if (argc != 3)
error("Usage: c from to");
if ((f1 = open(argv[1], O_RDONLY, 0)) == -1)
error("cp: can't open %s", argv[1]);
if ((f2 = creat(argv[2], PERMS)) == -1)
error("cp: can't create %s, mode %03o", argv[2], PERMS);
while ((n = read(f1, buf, BUFSIZ)) > 0)
if (write(f2, buf, n) != n)
error("cp: write error on file %s", argv[2]);
return 0;
}
#include <stdio.h>
#include <stdarg.h>
/* error函数: 打印一个出错信息,然后终止 */
void error(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "error:");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
exit (1);
}
相关文档:
2009-12-24 21:15:41
TURBO C 2.0 文件分类
·原创·
网上下载TURBO C 2.0很混乱,一直想把她整理一下,使各个实例分开,各个不同部分分开。断断续续花了很长时间,到今天终于整理完了。发帖出来给大家看看。有需要的 ......
//获得汉字的区位码
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes("啊");
int i1 = (short)(array[0] - ''\0'');
int i2 = (short)(array[1] - ''\0'');
//unicode解码方式下的汉字码
array = System.Text.Encoding.Unicode.GetBytes("啊");
i1 = (short)(arra ......
#include <windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
OPENFILENAME ofn;
//在内存中开辟一块空间,存放用户选取的文件名
char szFile[MAX_PATH];//MAX_PATH ......
左值性(lvalueness)在C/C++中是表达式的一个重要属性。只有通过一个左值表达式才能来引用及更改一个对象(object)的值。(某些情况下,右值表达式也能引用(refer)到某一个对象,并且可能间接修改该对象的值,后述)。
何谓对象?如果没有明确说明,这里说的对象,和狭义的类/对象(class/object) ......
C和C++的标准库
默认分类 2008-02-28 14:28 阅读3 评论0
字号: 大大 中中 小小
http://blog.chinaunix.net/u/6776/showart_186792.html C/C++深层探索
本小节我们概览一下C/C++标准库的全貌。
C/C++标准库的内 ......