| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 论坛
 上传资源
上传编程相关的资源,源源不断赚取资源分,以备将来下载之需
Yadann
文件大小:678.66 KB
文件类型:pdf
发布时间:2026-05-27 13:19:22
需资源分:2
下载次数:0
Tag:C语言函数
::资源简介::
函数名: write 
功 能: 写到一文件中 
用 法: int write(int handel, void *buf, int nbyte); 
程序例: 
#include <stdio.h> 
#include <stdlib.h> 
#include <fcntl.h> 
#include <sys\stat.h> 
#include <io.h> 
#include <string.h> 
int main(void) 

 int handle; 
 char string[40]; 
 int length, res; 
 /* 
 Create a file named "TEST.$$$" in the current directory and write 
 a string to it. If "TEST.$$$" already exists, it will be overwritten. 
 */ 
 if ((handle = open("TEST.$$$", O_WRONLY | O_CREAT | O_TRUNC, 
 S_IREAD | S_IWRITE)) == -1) 
 { 
 printf("Error opening file.\n"); 
 exit(1); 
 } 
 strcpy(string, "Hello, world!\n"); 
 length = strlen(string); 
 if ((res = write(handle, string, length)) != length) 
 { 
 printf("Error writing to the file.\n"); 
 exit(1); 
 } 
 printf("Wrote %d bytes to the file.\n", res); 
 close(handle); 
 return 0; 
}
::下载地址::

BCCN本地下载 
开通VIP
可免资源分下载所有资源
::下载本资源的人也下载了::
::作者其它资源::
 
>> 评论
 
热门Tag:
 
编程中国 版权所有,并保留所有权利。
Powered by BCCN 1.020, Processed in 0.005162 second(s)
Copyright©2010-2026, BCCN.NET, All Rights Reserved