当前位置: 首页 > news >正文

app推广渠道商淄博做网站seo

app推广渠道商,淄博做网站seo,手机能看的网站,昆明网站快速优化排名标准IO 头文件需求&#xff1a; #include <stdio.h>1.fopen和fclose (1)fopen fopen的函数功能是打开一个文件。 首先看看fopen的函数声明&#xff1a; FILE *fopen(const char *path, const char *mode);第一个参数path是文件地址&#xff0c;传入的是不可变的字符…

标准IO

头文件需求:

#include <stdio.h>

1.fopen和fclose

(1)fopen

fopen的函数功能是打开一个文件。
首先看看fopen的函数声明:

FILE *fopen(const char *path, const char *mode);

第一个参数path是文件地址,传入的是不可变的字符串;第二个参数是mode是指打开方式,传入的也是不可变的字符串;返回的是FILE指针。
mode的可选项主要有:

"r" Open text file for reading. The stream is positioned at the beginning of the file.
"r+" Open for reading and writing. The stream is positioned at the beginning of the file.
"w" Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
"w+" Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
"a" Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
"a+" Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.

(2)fclose

fclose的函数功能是关闭一个文件。
fclose的函数声明:

int fclose(FILE *fp);

传入的参数是FILE指针,即fopen创建的那个指针;成功则返回0,否则返回EOF,并将错误存储在errno中

附:Linux中系统调用的错误都存储于 errno中,errno由操作系统维护,存储就近发生的错误,即下一次的错误码会覆盖掉上一次的错误。

2.fgetc和fputc

(1)fgetc

fgetc的功能是从stream中读取下一个character。
函数声明如下:

int fgetc(FILE *stream);

传入的参数是stream来源即FILE指针。

(2)fputc

fputc的功能是将一个character写入到stream中。
函数原型是:

int fputc(int c, FILE *stream);

 第一个参数就是要写入的字符,虽然是int型,但是只用低八位(unsigned char);第二个参数即写入到的stream来源即FILE指针。

int main(int argc, char const *argv[])
{FILE *fp1 = fopen("1.txt", "r");FILE *fp2 = fopen("2.txt", "w");if(NULL == fp1){fprintf(stderr, "fp1 open error");}while(1){int a = fgetc(fp1);if(EOF == a){break;}fputc(a, fp2);}fclose(fp1);fclose(fp2);return 0;
}

3.fgets和fputs

(1)fgets

fgets的功能是从stream中读取至多一定数量的字符,并且存入buffer中,遇到'\n'或者EOF就停止读取。
函数声明:

char *fgets(char *s, int size, FILE *stream);

第一个参数是字符串buffer指针,传入的是char*,这里当然是可变的;第二个参数是至多读取的字符数,传入的是int;第三个参数就是stream来源即FILE指针。
这个函数把获取到的字符传入buffer后,还会自动在末尾加上'\0'表示字符串的结束。

(2)fputs
fputs的功能是将字符串s传到stream中。
函数声明是:
int fputs(const char *s, FILE *stream);

第一个参数是不可变的字符串,第二个参数就是要写到的stream来源这里是FILE指针。
字符串被写入stream后,还会自动在末尾加上'\0'表示结束。

(3)fgets与fputs综合运用复现copy
int main(int argc, char const *argv[])
{FILE *fp1 = fopen("5.txt", "r");FILE *fp2 = fopen("6.txt", "w");if(NULL == fp1 || NULL == fp2){fprintf(stderr, "fopen error");return 1;}while(1){char s[1024] = {0};if(NULL == fgets(s, sizeof(s), fp1)){break;}fputs(s, fp2);}return 0;
}

但是该函数不能拷贝二进制类型文件。 

 

http://www.dtcms.com/a/447049.html

相关文章:

  • 网站设计和美工一样吗推广引流图片
  • 网站建设专家工作内容厦门软件开发工资一般多少
  • dede中英文网站 视频网站建设 中企动力厨具
  • AI 大模型之spring alibaba篇
  • 《C++进阶之C++11》【智能指针】(上)
  • 网站域名注册哪个好重庆seo优化效果好
  • 漳州微网站建设公司哪家好番禺网站排名优化公司
  • 帮人做网站好挣吗看房子建设进度的网站
  • 做网站报价出名的先注册域名后建设网站可以吗
  • JVM自动内存管理
  • 五里店网站建设免费申请qq号注册新账号
  • 网站字体大小是多少合适园林景观设计效果图
  • Oracle 11g R2 物理冷备
  • 公司网站本地如何弄网站的建设主题
  • 搜索引擎网站优化推广电脑做网站服务器
  • Scade One 图形建模 - 数组操作算符
  • [工作流节点13] 发送邮件节点配置与邮件模板技巧 —— 从基础通知到智能邮件自动化
  • 河池网站制作dns服务器 域名不存在时 跳转到指定网站
  • 做网站那个程序好高端网站建设好处
  • 洞察人心,构建未来:INFJ性格在互联网产品与设计领域的职业优势
  • 忆达城市建设游戏网站wordpress升级文章编辑器
  • audio 之 BtHelper
  • 企业网站建设版本用动物做logo的旅游网站
  • 正常开发一个网站需要多少钱广告公司用的什么软件
  • 阿里巴巴网站被关闭了要怎么做网站开发需求分析参考文献
  • php 新闻类网站怎么做济宁百度推广电话
  • 如何看一个网站是谁做的如何做一款服装网站
  • wordpress 添加网页电商seo是什么意思
  • telnet server enable 概念及题目
  • jsp网站开发的环境配置过程一般网站 广告