ITPub博客

首页 > > > Linux c简单helloworld.

Linux c简单helloworld.

作者:dapan 时间:2020-05-04 22:48:50 0 删除 编辑
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#define LENGTH 100
main()
{
	int fd, len;
	char str[LENGTH];

	 fd = open("hello.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); /*
	 创建并打开文件 */
	 if (fd) {
	 write(fd, "Hello World", strlen("Hello World")); /*
	 写入字符串 */
	 close(fd);
	 }

	 fd = open("hello.txt", O_RDWR);
	 len = read(fd, str, LENGTH); /* 读取文件内容 */
	 str[len] = '\0';
	 printf("%s\n", str);
	 close(fd);
}

原文作者:;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2020-08-07

  • 博文量
    4504
  • 访问量
    87297