来源:www.cncfan.com | 2006-1-16 | (有3643人读过)
handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);
/* write 10 bytes to the file */ write(handle, buf, strlen(buf));
/* close the file */ close(handle); return 0; }
函数名: creatnew 功 能: 创建一个新文件 用 法: int creatnew(const char *filename, int attrib); 程序例:
#include #include #include #include #include
int main(void) { int handle; char buf[11] = "0123456789";
/* attempt to create a file that doesn't already exist */ handle = creatnew("DUMMY.FIL", 0);
if (handle == -1) printf("DUMMY.FIL already exists.\n"); else { printf("DUMMY.FIL successfully created.\n"); write(handle, buf, strlen(buf)); close(handle); } return 0; }
函数名: creattemp 功 能: 创建一个新文件或重写一个已存在的文件 用 法: int creattemp(const char *filename, int attrib); 程序例:
#include #include #include
int main(void) { int handle; char pathname[128];
strcpy(pathname, "\\");
/* create a unique file in the root directory */ handle = creattemp(pathname, 0);
printf("%s was the unique file created.\n", pathname); close(handle); return 0; }
函数名: cscanf 功 能: 从控制台执行格式化输入 用 法: int cscanf(char *format[,argument, ...]); 程序例:
#include
int main(void) { char string[80];
/* clear the screen */ clrscr();
/* Prompt the user for input */ cprintf("Enter a string with no spaces:");
/* read the input */ cscanf("%s", string);
/* display what was read */ cprintf("\r\nThe string entered is: %s", string); return 0; }
函数名: ctime 功 能: 把日期和时间转换为字符串 用 法: char *ctime(const time_t *time); 程序例:
#include #include
int main(void) { time_t t;
time(&t); printf("Today's date and time: %s\n", ctime(&t)); return 0; }
函数名: ctrlbrk 功 能: 设置Ctrl-Break处理程序 用 法: void ctrlbrk(*fptr)(void); 程序例:
#include #include
#define ABORT 0
int c_break(void) { printf("Control-Break pressed. Program aborting ...\n"); return (ABORT); }
int main(void) { ctrlbrk(c_break); for(;;) { printf("Looping... Press to quit:\n"); } return 0; }
|