write函数
来源:互联网 发布:java实现网络电话 编辑:程序博客网 时间:2024/06/07 05:14
收藏
69
write函数编辑
目录
1类型编辑
C语言函数
2函数名编辑
write
3功 能编辑
写到一文件中
4用 法编辑
write函数所在的头文件为 <unistd.h>
write有两种用法。一种是:
int write(int handle, void *buf, int nbyte);
handle 是文件描述符;
buf是指定的缓冲区,即指针,指向一段内存单元;
nbyte是要写入文件指定的字节数;返回值:写入文档的字节数(成功);-1(出错)
write函数把buf中nbyte写入文件描述符handle所指的文档,成功时返回写的字节数,错误时返回-1.
另一种是:write(const char* str,int n)
str是字符指针或字符数组,用来存放一个字符串。n是int型数,它用来表示输出显示字符串中字符的个数。
write("string",strlen("string");表示输出字符串常量
5程序例编辑
#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; }
0 0
- write函数
- write()函数
- read、write函数
- read()与write()函数
- read/write函数
- WRITE 函数的用法
- read/write函数
- read和write函数
- write()函数简介
- read && write函数
- read和write函数
- 【系统基础】write函数
- read, write 函数用法
- write()函数简介
- write函数不管用?
- linux之write函数
- FFMPEG write 函数
- read与write函数
- 安卓:调用真正系统默认短信应用发短信. (含解决4.4系统环聊问题, 含调低版本apk调用高版本系统api)
- C/S架构和B/S架构的概念和区别
- MySQL数据库引擎介绍、区别、创建和性能测试的深入分析
- 做个可以赚钱的宅男 - PTC网赚推荐
- Boost::Thread使用示例
- write函数
- C++之父评论C++与Java
- java中输入、输出流总结
- ASP.NET 图片下载
- 真理与文字
- objc delegate
- Redhat 出现丢包解决方法(ping: sendmsg: Operation not permitted)
- 为什么自媒体作者们突然开始讨论钱了?
- Android开发学习笔记1---环境搭建