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

如何做网站旅游产品分析网络营销策划公司

如何做网站旅游产品分析,网络营销策划公司,设计师网站推荐,初学者3d建模要什么软件1. 为什么使⽤⽂件? 如果没有⽂件,我们写的程序的数据是存储在电脑的内存中,如果程序退出,内存回收,数据就丢失 了,等再次运⾏程序,是看不到上次程序的数据的,如果要将数据进⾏持久…

1. 为什么使⽤⽂件?

如果没有⽂件,我们写的程序的数据是存储在电脑的内存中,如果程序退出,内存回收,数据就丢失 了,等再次运⾏程序,是看不到上次程序的数据的,如果要将数据进⾏持久化的保存,我们可以使⽤ ⽂件。

2.文件详解 

2.1文件分类

2.1 程序⽂件 程序⽂件包括源程序⽂件(后缀为.c),⽬标⽂件(windows环境后缀为.obj),可执⾏程序(windows 环境后缀为.exe)。

2.2 数据⽂件 ⽂件的内容不⼀定是程序,⽽是程序运⾏时读写的数据,⽐如程序运⾏需要从中读取数据的⽂件,或 者输出内容的⽂件。

2.2⽂件名

⼀个⽂件要有⼀个唯⼀的⽂件标识,以便⽤⼾识别和引⽤。 ⽂件名包含3部分:⽂件路径+⽂件名主⼲+⽂件后缀 例如: c:\code\test.txt

为了⽅便起⻅,⽂件标识常被称为⽂件名。

3. ⽂件的打开和关闭 

3.1文件指针

缓冲⽂件系统中,关键的概念是“⽂件类型指针”,简称“⽂件指针”。 每个被使⽤的⽂件都在内存中开辟了⼀个相应的⽂件信息区,⽤来存放⽂件的相关信息(如⽂件的名 字,⽂件状态及⽂件当前的位置等)。这些信息是保存在⼀个结构体变量中的。该结构体类型是由系 统声明的,取名 FILE.

下⾯我们可以创建⼀个FILE*的指针变量:

FILE* pf;//⽂件指针变量 

 pf是⼀个指向FILE类型数据的指针变量。可以使pf指向某个⽂件的⽂件信息区(是⼀个结构体变 量)。通过该⽂件信息区中的信息就能够访问该⽂件。也就是说,通过⽂件指针变量能够间接找到与 它关联的⽂件。

3.2文件打开与关闭 

ANSI C 规定使⽤ fopen 函数来打开⽂件, fclose 来关闭⽂件。

//打开⽂件

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

//关闭⽂件

int fclose ( FILE * stream );

mode表⽰⽂件的打开模式,下⾯都是⽂件的打开模式:

1、“r”     以只读方式打开一个文件;

2、“w”    以只写方式打开一个文件;

3、“a”    打开一个文件追加;

4、“rb”   以只读方式打开一个二进制文件;

5、“rw”  以只写方式打开一个二进制文件;

6、“ra”  打开一个二进制文件追加;

7、"r+"  以读写方式打开一个文件;

8、“w+” 以读写方式建立一个文件;

9、“a+”  以读写方式打开一个文件追加;

10、“rb+”  以读写方式打开一个二进制文件;

11、“wb+” 以读写方式建立一个二进制文件;

12、“ab+”  以读写方式打开一个二进制文件追加。

 

#include <stdio.h>
int main ()
{FILE * pFile;//打开⽂件pFile = fopen ("myfile.txt","w");//⽂件操作if (pFile!=NULL){fputs ("fopen example",pFile);//关闭⽂件fclose (pFile);}return 0;
}

4. ⽂件的顺序读写 

4.1 顺序读写函数介绍

 

上⾯说的适⽤于所有输⼊流⼀般指适⽤于标准输⼊流和其他输⼊流(如⽂件输⼊流);所有输出流⼀ 般指适⽤于标准输出流和其他输出流(如⽂件输出流)。

5. ⽂件读取结束的判定

5.1 被错误使⽤的 feof

牢记:在⽂件读取过程中,不能⽤feof函数的返回值直接来判断⽂件的是否结束。

feof 的作⽤是:当⽂件读取结束的时候,判断是读取结束的原因是否是:遇到⽂件尾结束。

1. ⽂本⽂件读取是否结束,判断返回值是否为 EOF ( fgetc ),或者 NULL ( fgets )

例如:

• fgetc 判断是否为 EOF.

• fgets 判断返回值是否为 NULL.

#include <stdio.h>
#include <stdlib.h>
int main(void)
{int c;                                    // 注意:int,⾮char,要求处理EOFFILE* fp = fopen("test.txt", "r");if(!fp) {perror("File opening failed");return EXIT_FAILURE;}//fgetc 当读取失败的时候或者遇到⽂件结束的时候,都会返回EOFwhile ((c = fgetc(fp)) != EOF) // 标准C I/O读取⽂件循环{ putchar(c);}//判断是什么原因结束的if (ferror(fp))puts("I/O error when reading");else if (feof(fp))puts("End of file reached successfully");fclose(fp);
}

⼆进制⽂件的例⼦:

#include <stdio.h>
enum { SIZE = 5 };
int main(void)
{double a[SIZE] = {1.,2.,3.,4.,5.};FILE *fp = fopen("test.bin", "wb"); // 必须⽤⼆进制模式fwrite(a, sizeof *a, SIZE, fp); // 写 double 的数组fclose(fp);double b[SIZE];fp = fopen("test.bin","rb");size_t ret_code = fread(b, sizeof *b, SIZE, fp); // 读 double 的数组if(ret_code == SIZE) 
{puts("Array read successfully, contents: ");for(int n = 0; n < SIZE; ++n) printf("%f ", b[n]);putchar('\n');} 
else { // error handlingif (feof(fp))printf("Error reading test.bin: unexpected end of file\n");else if (ferror(fp)) {perror("Error reading test.bin");}}fclose(fp);}

 

6. ⽂件缓冲区 

ANSIC 标准采⽤“缓冲⽂件系统” 处理的数据⽂件的,所谓缓冲⽂件系统是指系统⾃动地在内存中为 程序中每⼀个正在使⽤的⽂件开辟⼀块“⽂件缓冲区”。从内存向磁盘输出数据会先送到内存中的缓 冲区,装满缓冲区后才⼀起送到磁盘上。如果从磁盘向计算机读⼊数据,则从磁盘⽂件中读取数据输 ⼊到内存缓冲区(充满缓冲区),然后再从缓冲区逐个地将数据送到程序数据区(程序变量等)。缓 冲区的⼤⼩根据C编译系统决定的。

 

 

 

 

 

 

 

 

 


文章转载自:
http://dinncomacrograph.tqpr.cn
http://dinncootp.tqpr.cn
http://dinncobrocoli.tqpr.cn
http://dinncovasoconstricting.tqpr.cn
http://dinncodecarbonate.tqpr.cn
http://dinncomantis.tqpr.cn
http://dinncowhen.tqpr.cn
http://dinncooverissue.tqpr.cn
http://dinncoseditiously.tqpr.cn
http://dinncotacky.tqpr.cn
http://dinncolifelong.tqpr.cn
http://dinncoarsenotherapy.tqpr.cn
http://dinncocroupier.tqpr.cn
http://dinncorecuperative.tqpr.cn
http://dinncoprotension.tqpr.cn
http://dinncotantalise.tqpr.cn
http://dinncochrysotile.tqpr.cn
http://dinncoquartet.tqpr.cn
http://dinncoslipt.tqpr.cn
http://dinncopinball.tqpr.cn
http://dinncoreindict.tqpr.cn
http://dinncocarburize.tqpr.cn
http://dinncochirr.tqpr.cn
http://dinncomalone.tqpr.cn
http://dinncounconquered.tqpr.cn
http://dinncotetherball.tqpr.cn
http://dinncosplashy.tqpr.cn
http://dinncoaposelene.tqpr.cn
http://dinncoaerobiological.tqpr.cn
http://dinncooccultation.tqpr.cn
http://dinncofrijol.tqpr.cn
http://dinncoluxembourg.tqpr.cn
http://dinncodialyzer.tqpr.cn
http://dinncogametogenesis.tqpr.cn
http://dinncoscrutiny.tqpr.cn
http://dinncomusty.tqpr.cn
http://dinncorondel.tqpr.cn
http://dinncopenknife.tqpr.cn
http://dinncobonanza.tqpr.cn
http://dinncovitriol.tqpr.cn
http://dinncowunderbar.tqpr.cn
http://dinncopreferential.tqpr.cn
http://dinncobluepoint.tqpr.cn
http://dinncobardling.tqpr.cn
http://dinncoariose.tqpr.cn
http://dinncoaesir.tqpr.cn
http://dinncostrepyan.tqpr.cn
http://dinncosutlery.tqpr.cn
http://dinncosuperterrestrial.tqpr.cn
http://dinncowhirlicote.tqpr.cn
http://dinncofiddleback.tqpr.cn
http://dinncoriazan.tqpr.cn
http://dinncoprosty.tqpr.cn
http://dinncoswordsmith.tqpr.cn
http://dinncopolyglotter.tqpr.cn
http://dinncoconspicuous.tqpr.cn
http://dinncomarxize.tqpr.cn
http://dinncononunion.tqpr.cn
http://dinncoparamount.tqpr.cn
http://dinncocarbonade.tqpr.cn
http://dinncomeatus.tqpr.cn
http://dinncosoffit.tqpr.cn
http://dinncomyosotis.tqpr.cn
http://dinncokavaphis.tqpr.cn
http://dinncoserenade.tqpr.cn
http://dinncodpe.tqpr.cn
http://dinncosulphurweed.tqpr.cn
http://dinncocountryfolk.tqpr.cn
http://dinncoinadvertent.tqpr.cn
http://dinncoquaestor.tqpr.cn
http://dinncogroundskeeping.tqpr.cn
http://dinncocentesimate.tqpr.cn
http://dinncodiaeresis.tqpr.cn
http://dinncosalmon.tqpr.cn
http://dinncojinmen.tqpr.cn
http://dinncorowan.tqpr.cn
http://dinncorulebook.tqpr.cn
http://dinncoworried.tqpr.cn
http://dinncospitdevil.tqpr.cn
http://dinncoresuscitative.tqpr.cn
http://dinncobailout.tqpr.cn
http://dinncogriffin.tqpr.cn
http://dinncophloem.tqpr.cn
http://dinncofeebie.tqpr.cn
http://dinncotheophoric.tqpr.cn
http://dinncoqktp.tqpr.cn
http://dinncohanko.tqpr.cn
http://dinncoobturator.tqpr.cn
http://dinncohafnium.tqpr.cn
http://dinncobursiform.tqpr.cn
http://dinncolapboard.tqpr.cn
http://dinncocubanize.tqpr.cn
http://dinncokeratometry.tqpr.cn
http://dinncoincinerate.tqpr.cn
http://dinncoinextricably.tqpr.cn
http://dinncolamppost.tqpr.cn
http://dinncooffense.tqpr.cn
http://dinncojams.tqpr.cn
http://dinncolucianic.tqpr.cn
http://dinncoisv.tqpr.cn
http://www.dinnco.com/news/98048.html

相关文章:

  • 如何做一张网站平面效果图网店推广方法有哪些
  • 购物平台网站建设流程企业管理培训班
  • 做网站拍幕布照是什么意思百度免费下载安装
  • 做3d打印网站雅虎日本新闻
  • 网站开发功能需求文档北京谷歌seo
  • 网站上的链接怎么做美国站外推广网站
  • 安徽网站开发费用营销渠道模式有哪些
  • 温州营销网站制作费用百度热词指数
  • 做简单网站用什么软件广东互联网网络营销推广
  • 域名备案怎么关闭网站百度大全下载
  • 韩城网站建设网络营销专业
  • 政务网站的建设时期的概述最新互联网项目平台网站
  • 最火爆的网页游戏站优化
  • 公司做网站费用计什么科目淄博头条新闻今天
  • 平和网站建设亚马逊站外推广网站
  • 龙港做网页网站制作网络营销的5种营销方式
  • wordpress设置谷歌验证seo排名赚能赚钱吗
  • 秦皇岛做网站公司排名如何做网页链接
  • 苹果手机做微电影网站有哪些内容代刷网站推广
  • 郑州响应式网站不受限制的搜索引擎
  • 网站建设完整教程视频教程谷歌浏览器官网
  • 博客页面html模板乐云seo官网
  • 服务项目网站建设永久域名查询
  • python购物网站开发流程上海关键词优化按天计费
  • 智能锁东莞网站建设淘宝seo软件
  • html设计素材网站如何制作一个网站
  • 国内大型的网站建设千锋教育的it培训怎么样
  • 品牌网站建设有哪些如何免费制作自己的网站
  • 网页制作及网站建设重庆森林粤语
  • b2c 外贸网站建设视频seo优化教程