|
Turbo C 2.0、Borland C++库函数及用例(15) cprintf("Hello world\r\n"); /* wait for a key */ getch(); return 0; } 函数名: cputs 功 能: 写字符到屏幕 用 法: void cputs(const char *string); 程序例:#include <conio.h>int main(void) { /* clear the screen */ clrscr(); /* create a text window */ window(10, 10, 80, 25); /* output some text in the window */ cputs("This is within the window\r\n"); /* wait for a key */ getch(); return 0; } 函数名: _creat, creat 功 能: 创建一个新文件或重写一个已存在的文件 用 法: int creat (const char *filename, int permiss); 程序例:#include <sys\stat.h> #include <string.h> #include <fcntl.h> #include <io.h>int main(void) { int handle; char buf[11] = "0123456789"; /* change the default file mode from text to binary */ _fmode = O_BINARY; /* create a binary file for reading and writing */ 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 <string.h> #include <stdio.h> #include <errno.h> #include <dos.h> #include <io.h>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 <string.h> #include <stdio.h> #include <io.h>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);
|