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

网站里面的视频功能怎么做网站名注册

网站里面的视频功能怎么做,网站名注册,桂林做,海外网络推广培训本章重点#xff1a; 什么是文件 文件名 文件类型 文件缓冲区 文件指针 文件的打开和关闭文件的顺序读写文件的随机读写文件结束的判定 1. 什么是文件 磁盘上的文件是文件。 但是在程序设计中#xff0c;我们一般谈的文件有两种#xff1a;程序文件、数据文件 1.1 程序文件…本章重点 什么是文件 文件名 文件类型 文件缓冲区 文件指针 文件的打开和关闭文件的顺序读写文件的随机读写文件结束的判定 1.  什么是文件 磁盘上的文件是文件。 但是在程序设计中我们一般谈的文件有两种程序文件、数据文件 1.1 程序文件 包括源程序文件后缀为.c,目标文件windows环境后缀为.obj,可执行程序windows环境后缀为.exe。 1.2 数据文件 文件的内容不一定是程序而是程序运行时读写的数据比如程序运行需要从中读取数据的文件或者输出内容的文件。 1.3 文件名 一个文件要有一个唯一的文件标识以便用户识别和引用。文件名包含3部分文件路径文件名主干文件后缀 例如 c:\code\test.txt 为了方便起见文件标识常被称为文件名。 2. 文件的打开和关闭 2.1 文件指针 缓冲文件系统中关键的概念是“文件类型指针”简称“文件指针”。 每个被使用的文件都在内存中开辟了一个相应的文件信息区用来存放文件的相关信息如文件的名字文件状态及文件当前的位置等。这些信息是保存在一个结构体变量中的。该结构体类型是有系统声明的取名FILE. 例如,VS2008编译环境提供的 stdio.h头文件中有以下的文件类型申明 struct _iobuf {char *_ptr;int _cnt;char *_base;int _flag;int _file;int _charbuf;int _bufsiz;char *_tmpfname; }; typedef struct _iobuf FILE; 不同的C编译器的FILE类型包含的内容不完全相同但是大同小异。 每当打开一个文件的时候系统会根据文件的情况自动创建一个FILE结构的变量并填充其中的信息使用者不必关 心细节。 一般都是通过一个FILE的指针来维护这个FILE结构的变量这样使用起来更加方便。 下面我们可以创建一个FILE*的指针变量: FILE* pf;//文件指针变量 定义pf是一个指向FILE类型数据的指针变量。可以使pf指向某个文件的文件信息区是一个结构体变量。通过该文 件信息区中的信息就能够访问该文件。也就是说通过文件指针变量能够找到与它关联的文件。  2.2 文件的打开与关闭 int main() {//相对路径//绝对路径///Users/fan/Documents/c_study/c_test26/data.txt//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件//关闭文件fclose(pf);pf NULL;return 0; } 3. 文件的顺序读写 3.1 顺序读写函数介绍 int main() {//相对路径//绝对路径///Users/fan/Documents/c_study/c_test26/data.txt//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,w);if (pf NULL){perror(fopen);return 1;}//读文件//写文件// fputc(a,pf);// fputc(b,pf);// fputc(c,pf);int i 0;for (i 0; i 26; i){fputc(ai,pf);}//关闭文件fclose(pf);pf NULL;return 0; } int main() {//相对路径//绝对路径///Users/fan/Documents/c_study/c_test26/data.txt//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件int ch fgetc(pf);printf(%c\n,ch); //ach fgetc(pf);printf(%c\n,ch); //bch fgetc(pf);printf(%c\n,ch); //cch fgetc(pf);printf(%c\n,ch);//d//写文件// fputc(a,pf);// fputc(b,pf);// fputc(c,pf);// int i 0;// for (i 0; i 26; i)// {// fputc(ai,pf);// }//关闭文件fclose(pf);pf NULL;return 0; } int main() {//相对路径//绝对路径///Users/fan/Documents/c_study/c_test26/data.txt//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件// int ch fgetc(pf);// printf(%c\n,ch); //a// ch fgetc(pf);// printf(%c\n,ch); //b// ch fgetc(pf);// printf(%c\n,ch); //c// ch fgetc(pf);// printf(%c\n,ch);//d//写文件// fputc(a,pf);// fputc(b,pf);// fputc(c,pf);// int i 0;// for (i 0; i 26; i)// {// fputc(ai,pf);// }// fputs(hello fan\n,pf);// fputs(hello fanfan\n,pf);//读文件 - 读一行char arr[10] {0};fgets(arr,15,pf);printf(%s\n,arr);fgets(arr,15,pf);printf(%s\n,arr);//关闭文件fclose(pf);pf NULL;return 0; } struct S {int a;float s; };int main() {//相对路径//绝对路径///Users/fan/Documents/c_study/c_test26/data.txt//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//写文件//struct S s {100,3.14f};//fprintf(pf,%d %f,s.a,s.s);struct S s {0};fscanf(pf,%d %f,(s.a),(s.s));printf(%d %f,s.a,s.s);//关闭文件fclose(pf);pf NULL;return 0; } struct S {int a;float s;char str[10]; };int main() {struct S s {99, 6.18f, bit};//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,wb);if (pf NULL){perror(fopen);return 1;}//写文件fwrite(s,sizeof(struct S),1,pf);//关闭文件fclose(pf);pf NULL;return 0; } int main() {struct S s {0};//打开文件FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,rb);if (pf NULL){perror(fopen);return 1;}//读文件fread(s,sizeof(struct S),1,pf);printf(%d %f %s\n,s.a,s.s,s.str);//关闭文件fclose(pf);pf NULL;return 0; } 4. 文件的随机读写 4.1 fseek 根据文件指针的位置和偏移量来定位文件指针。 int fseek ( FILE * stream, long int offset, int origin ); int main() {FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件//定位文件指针到fint ch fgetc(pf);printf(%c\n,ch); //ach fgetc(pf);printf(%c\n,ch); //bch fgetc(pf);printf(%c\n,ch); //c ch fgetc(pf);printf(%c\n,ch); //dfseek(pf,-3,SEEK_END);ch fgetc(pf);printf(%c\n,ch);//关闭文件fclose(pf);pf NULL;return 0; } 4.2 ftell 返回文件指针相对于起始位置的偏移量 long int ftell ( FILE * stream ); int main() {FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件//定位文件指针到fint ch fgetc(pf);printf(%c\n,ch); //ach fgetc(pf);printf(%c\n,ch); //bch fgetc(pf);printf(%c\n,ch); //c ch fgetc(pf);printf(%c\n,ch); //d// fseek(pf,-3,SEEK_END);// ch fgetc(pf);// printf(%c\n,ch);int pos ftell(pf);printf(%d\n,pos); //4//关闭文件fclose(pf);pf NULL;return 0; } 4.3 rewind  让文件指针的位置回到文件的起始位置 void rewind ( FILE * stream ); int main() {FILE* pf fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pf NULL){perror(fopen);return 1;}//读文件//定位文件指针到fint ch fgetc(pf);printf(%c\n,ch); //ach fgetc(pf);printf(%c\n,ch); //bch fgetc(pf);printf(%c\n,ch); //c ch fgetc(pf);printf(%c\n,ch); //d// fseek(pf,-3,SEEK_END);// ch fgetc(pf);// printf(%c\n,ch);// int pos ftell(pf);// printf(%d\n,pos); //4rewind(pf); //回到起始位置ch fgetc(pf);printf(%c\n,ch); //a//关闭文件fclose(pf);pf NULL;return 0; } 5. 文本文件和二进制文件 6. 文件读取结束的判断   6.1 被错误使用的feof 牢记在文件读取过程中不能用feof函数的返回值直接用来判断文件的是否结束。 而是应用于当文件读取结束的时候判断是读取失败结束还是遇到文件尾结束。 1. 文本文件读取是否结束判断返回值是否为EOF fgetc或者NULLfgets 例如 fgetc判断是否为EOF. fgets判断返回值是否为NULL. 2. 二进制文件的读取结束判断判断返回值是否小于实际要读的个数。 例如 fread判断返回值是否小于实际要读的个数。 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); }//拷贝文件 //拷贝data.txt文件产生一个新文件data1.txtint main() {FILE* pfRead fopen(/Users/fan/Documents/c_study/c_test26/data.txt,r);if (pfRead NULL){perror(open file for read);return 1;}FILE* pfWrite fopen(/Users/fan/Documents/c_study/c_test26/data2.txt,w);if (pfWrite NULL){perror(open file for write);fclose(pfRead);pfRead NULL;return 1;}//读写文件int ch 0;while((ch fgetc(pfRead)) ! EOF){fputc(ch,pfWrite);}//关闭文件fclose(pfRead);pfRead NULL;fclose(pfWrite);pfWrite NULL;return 0; } 7. 文件缓冲区
http://www.w-s-a.com/news/637448/

相关文章:

  • 网站游戏下载厦门php网站建设
  • 沈阳关键词网站排名一台服务器做两个网站吗
  • 哪个行业该做网站但是没有做dom手表官方网站
  • 网站建设费 大创wordpress中函数get
  • 怎样建设个自己的网站首页有没有专门教做扯面的网站
  • 网站后台怎么添加模板教育类网站开发公司
  • 网站的外链是什么php创建一个网站
  • 语文建设 官方网站网络工程可以从事什么工作
  • 无锡便宜做网站如何下载网站模板
  • 南宁高端网站网络小说网站推广策划方案
  • 苏州网站制作方法建设银行 网站
  • 技术网站推广范例素材网站哪个好
  • 网站找人做的他能登管理员吗网站建设一般多少钱
  • 衡水哪有做网站的wordpress主题站主题
  • 网络建设的流程网站公司注册资本
  • 杭州旅游团购网站建设建立一个网站需要哪些步骤
  • 实木餐桌椅网站建设浦东网站建设哪家好
  • 高端手机网站定制网站网络推广推广
  • 做网站的颜色大学网站群建设方案
  • 淄博学校网站建设哪家好网站集约化建设规范
  • 专业论坛网站有哪些如何制作h5页面视频
  • 南京整站优化网站备案负责人一定要法人
  • 北京正规网站建设公司php网站开发实训感想
  • 织梦网站地图怎么做腾讯网站开发语言
  • 站长之家alexa排名wordpress html 标签
  • WordPress建站主机推荐工程公司的经营范围
  • 做网站要注意哪一点网站需求分析的重要
  • 设计作品网站怎么开网站
  • 上海网站开发制作建设网站的建设费用包括
  • 上海网站建设网站开发亚洲杯篮球直播在什么网站