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);
}
相关文档:
DllImport所在的名字空间 using System.Runtime.InteropServices;
[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
private void button19_Click(obj ......
http://www.ddj.com/cpp/221600722
Q: HOW DO I... put timers with default actions in my C code?
A: Many times, we need to write programs that will only wait a certain specified amount of time for a user to do something. After that time, we need to assume that the user isn't going to do anything and ......
看数据结构裢栈的时候写了这么一段代码
#include<stdio.h>
#include<stdlib.h>
struct linkstack
{
int data;
struct linkstack *next;
};
int initstack(linkstack * S)
{
S = (linkstack *)malloc(sizeof(linkstack));
if(S == NULL) return 0;
S->next = NULL;
return 1;
}
int main(int ......
头文件的作用
早期的编程语言如Basic、Fortran 没有头文件的概念,C++/C 语言的初学者虽然会用使用头文件,但常常不明其理。这里对头文件的作用略作解释:
(1)通过头文件来调用库功能。在很多场合,源代码不便(或不准)向用户公布,只要向用户提供头文件和二进制的库即可。用户只需要按照头文件中的接口声明来调用库功 ......
在VC6中使用c API方式连接MySQL数据库
一、环境配置
1、在MySql的官方网站下载mysql-connector-c-noinstall,并将解压后的bin和include文件夹拷贝到Mysql的安装目录
2、设置VC6环境,在vc工具-选项-目录,加入刚才的Include文件夹的路径,例如:C:\Program Files\MySQL\MySQL Server 5.1\include
二、工程设置
3、将li ......