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

做网站拍幕布照是什么意思百度免费下载安装

做网站拍幕布照是什么意思,百度免费下载安装,百度站内搜索提升关键词排名,陶瓷 网站模板目录 字符方式读入文件 数据块方式读写文件 文件定位与随机读写 文件中数据的修改 字符方式读入文件 1.向文件中写入(输入字符) 用 fputc 函数或 puts 函数可以把一个字符写到磁盘文件中去。 int fputc(int ch,FILE * fp) ch 是要输出的字符&#…

目录

字符方式读入文件

数据块方式读写文件

文件定位与随机读写

文件中数据的修改


字符方式读入文件

1.向文件中写入(输入字符)

        用 fputc 函数或 puts 函数可以把一个字符写到磁盘文件中去。

int fputc(int ch,FILE * fp)

        ch 是要输出的字符,他可以是一个字符常量,也可以是一个字符变量;fp是文件指针变量,已经指向了一个由fopen函数打开的文件。

        功能:fputc(ch,fp)函数将字符输入到fp所指向的流式文件中去。如果输出成功,返回值就是输入的字符,失败则返回EOF。

从键盘输入遗传字符,以回车符\n结束,然后输入到磁盘文件中去

#include<stdio.h>
#include<stdlib.h>
int main()	
{//从键盘输入遗传字符,以回车符\n结束,然后输入到磁盘文件中去FILE * fp;char ch;if((fp=fopen("output1.txt","w"))==NULL){printf("无法创建文件!");exit(0); }while((ch=getchar())!='\n'){fputc(ch,fp);}fclose(fp);return 0;
}

2.从文件中读出一个字符

        用 fgetc 函数或者 getc 函数可以从磁盘中读出一个字符。

int fgetc(FILE * fp)

        从磁盘文键逐个读入字符,并在终端输出

#include<stdio.h>
#include<stdlib.h>
int main()
{//从磁盘文键逐个读入字符,并在终端输出FILE * fp;char ch;if((fp=fopen("output1.txt","r"))==NULL){printf("无法打开文件!\n");exit(0);	} while((ch=fgetc(fp))!=EOF){putchar(ch);}fclose(fp);return 0;
}

3.向文件中写入一个字符串

        用 fputs 函数可以把一个字符串输入到指定的流式文件中,其原型为

int fputs(char * fp,FILE * stream)

        其中,string为字符串,stream为文件指针。

 把指针string所指向的字符串输出到文件指针stream所指向的文件中,但字符串结束符‘\0’不输出

 从键盘输入若干行字符,把他们输出到磁盘文件中保存起来。

#include<stdio.h>
#include<stdlib.h>
int main()
{//从键盘输入若干行字符,把他们输出到磁盘文件中保存起来。FILE * fp;char string[81];if((fp=fopen("data.txt","w"))==NULL){printf("未找到此文件!");exit(0);	} while(gets(string)!=NULL)//ctrl+Z结束 {fputs(string,fp);fputc('\n',fp);//在每个字符串后加一个换行符 }fclose(fp);return 0;
}

数据块方式读写文件

使用数据块的方式对二进制问价进行读写操作,涉及的函数有两个:fread() 和 fwrite() 。

建立学生档案文件,每个记录包括学生的姓名,性别,年龄和入学总分 

#include<stdio.h>
#include<stdlib.h>
struct student
{char name[10];char sex;int age;float score;
};
int main()
{FILE * fp;struct student stud;char str[80],ch='y';if((fp=fopen("stud2.rec","wb"))==NULL)//二进制只写方式打开 {printf("无法打开文件!\n");exit(0);}while(ch=='y'||ch=='Y'){printf("输入姓名:");gets(stud.name);printf("输入性别:");gets(str);stud.sex=str[0];printf("输入年龄:");gets(str);stud.age=atoi(str);//年龄:将字符串转换为整型 printf("输入分数:");gets(str);stud.score=atof(str);//分数:将字符串转换为浮点型fwrite(&stud,sizeof(stud),1,fp);//写入数据到文件do{printf("继续输入:(y/n)?  ");gets(str);ch=str[0];} while(!(ch=='y'||ch=='n'||ch=='Y'||ch=='N'));}fclose(fp);return 0;
}

从磁盘文件按记录读取数据,并显示读入的内容,直到文件尾

#include<stdio.h>
#include<stdlib.h>
struct student
{char name[10];char sex;//'M',或'F' int age;float score;
};
int main()
{//从磁盘文件按记录读取数据,并显示读入的内容,直到文件尾struct student stud;FILE * fp;if((fp=fopen("stud2.rec","rb"))==NULL)	{printf("无法打开文件stud2.rec!\n");exit(0); }while(fread(&stud,sizeof(stud),1,fp)==1){printf("\n姓名:%s",stud.name);printf("\n性别:%c",stud.sex);printf("\n年龄:%d",stud.age);printf("\n分数:%.2f",stud.score);} printf("\n");fclose(fp);return 0;
}

文件定位与随机读写

文件的定位:利用fesk()和ftell()函数编写程序测量一个文件的长度 

#include<stdio.h>
#include<stdlib.h> 
//文件的定位
//利用fesk()和ftell()函数编写程序测量一个文件的长度 
long filesize(FILE * fp)
{long curpos,length;//当前文件读写位置指针相当于文件开头的位移量 curpos=ftell(fp);//保存文件的当前读写位置指针 fseek(fp,0L,SEEK_END);//文件读写位置指针置于文件尾端length=ftell(fp);//求文件长度fseek(fp,curpos,SEEK_SET);//恢复文件的原读写位置的指针return length; 
}
long filesize(FILE * stream);
int main()
{FILE * stream;char filename[10];printf("\n输入文件名:");scanf("%s",filename);if((stream=fopen(filename,"rb"))==NULL){printf("无法打开文件:%s\n",filename);exit(0);}printf("%s的文件大小是%ld(byte)\n",filename,filesize(stream));fclose(stream);return 0;
}

随机读写: 

由之前建立的学生入学档案的磁盘文件stud.rec中,假设学生按照分数升序排列。
现要求设计一个程序,输入一个整型值给n,输出分数最高的n个学生记录,即排在尾部的n个学生记录 

#include<stdio.h>
#include<stdlib.h>
struct student
{char name[10];char sex;//'M',或'F' int age;float score;
};
//由之前建立的学生入学档案的磁盘文件stud.rec中,假设学生按照分数升序排列。
//现要求设计一个程序,输入一个整型值给n,输出分数最高的n个学生记录,即排在尾部的n个学生记录 
int main()
{FILE * fp;struct student stud;int n;if((fp=fopen("stud.rec","rb"))==NULL){printf("无法打开文件");exit(0);	} printf("\n请输入一个整数:");scanf("%d",&n);fseek(fp,-n*sizeof(stud),SEEK_END); //定位到倒数第n个学生记录while(fread(&stud,sizeof(stud),1,fp)==1){printf("\n姓名:%s",stud.name);printf("\n性别:%c",stud.sex);printf("\n年龄:%d",stud.age);printf("\n分数:%.2f",stud.score);	} return 0;
}

文件中数据的修改

将之前的成绩表中的女生成绩加五分

#include<stdio.h>
#include<stdlib.h>
struct student
{char name[10];char sex;//'M',或'F' int age;float score;
};
int main()
{//从磁盘文件按记录读取数据,并显示读入的内容,直到文件尾struct student stud;FILE * fp;if((fp=fopen("stud.rec","rb"))==NULL)	{printf("无法打开文件stud2.rec!\n");exit(0); }while(fread(&stud,sizeof(stud),1,fp)==1){printf("\n姓名:%s",stud.name);printf("\n性别:%c",stud.sex);printf("\n年龄:%d",stud.age);printf("\n分数:%.2f",stud.score);} printf("\n");fclose(fp);return 0;
}

输入一个学生的姓名,编写程序将stud.rec中该学生的记录删除 

#include<stdio.h>
#include<stdlib.h>
#include<string.h> 
struct student
{char name[10];char sex;//'M',或'F' int age;float score;
};
//输入一个学生的姓名,编写程序将stud.rec中该学生的记录删除 
int main()
{char name[10];FILE * fp_old,* fp_new;struct student stud;if((fp_old=fopen("stud.rec","rb"))==0)//读方式打开原数据文件 {printf("\n不能打开文件");exit(0); }if((fp_new=fopen("stud3.rec","wb"))==0)//写方式创建新数据文件 {printf("\n不能创建文件");exit(0); } printf("请输入要删除的学生姓名:");gets(name);while(fread(&stud,sizeof(stud),1,fp_old)==1){//在原文件中读取一个学生记录在stud中if(strcmp(stud.name,name)!=0){fwrite(&stud,sizeof(stud),1,fp_new);	} } fclose(fp_old);fclose(fp_new);remove("stud.rec");//删除原文件rename("stud3.rec","stud.rec"); //将新文件重命名 return 0;
}

向文件中插入数据

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{char name[10];char sex;//'M',或'F' int age;float score;
};
int main()
{FILE * fp;struct student x,t={"Alex",'f',20,566};if((fp=fopen("stud.rec","a+b"))==0){printf("\n\t无法打开文件!\n");exit(0);}fread(&x,sizeof(struct student),1,fp);//从文件中读一条学生记录fseek(fp,0L,SEEK_END); fwrite(&t,sizeof(struct student),1,fp);//将t中的数据追加到文件尾rewind(fp);while(fread(&x,sizeof(struct student),1,fp)==1){printf("\n%15s%4c%8d%8.2f",x.name,x.sex,x.age,x.score);	} fclose(fp);return 0;
}


文章转载自:
http://dinncoquinquelateral.tpps.cn
http://dinncoeolithic.tpps.cn
http://dinncooverbuild.tpps.cn
http://dinncoheteromorphic.tpps.cn
http://dinncotripitaka.tpps.cn
http://dinncosoursop.tpps.cn
http://dinncocommonly.tpps.cn
http://dinncoyttrialite.tpps.cn
http://dinncobikini.tpps.cn
http://dinncodockage.tpps.cn
http://dinncorevenant.tpps.cn
http://dinncodissonantal.tpps.cn
http://dinncoravenous.tpps.cn
http://dinncojilt.tpps.cn
http://dinncotrento.tpps.cn
http://dinncoforktailed.tpps.cn
http://dinncounclaimed.tpps.cn
http://dinncocontrollership.tpps.cn
http://dinncomedievalism.tpps.cn
http://dinncotensely.tpps.cn
http://dinncointerrupter.tpps.cn
http://dinncoplainly.tpps.cn
http://dinnconephric.tpps.cn
http://dinncochildish.tpps.cn
http://dinncoprotestant.tpps.cn
http://dinncologistics.tpps.cn
http://dinncohyte.tpps.cn
http://dinncoremission.tpps.cn
http://dinncoplagiarism.tpps.cn
http://dinncophilosophic.tpps.cn
http://dinncodialogically.tpps.cn
http://dinncochang.tpps.cn
http://dinncosideburns.tpps.cn
http://dinncovirilocal.tpps.cn
http://dinnconationalize.tpps.cn
http://dinncodurkheimian.tpps.cn
http://dinncosnide.tpps.cn
http://dinncopyrrhic.tpps.cn
http://dinncohumility.tpps.cn
http://dinncotad.tpps.cn
http://dinncogearbox.tpps.cn
http://dinncoregardant.tpps.cn
http://dinncomyocardia.tpps.cn
http://dinncobipartisan.tpps.cn
http://dinncopizzicato.tpps.cn
http://dinncohekla.tpps.cn
http://dinncocellulated.tpps.cn
http://dinncopuzzolana.tpps.cn
http://dinncosaltimbanque.tpps.cn
http://dinncospringiness.tpps.cn
http://dinncowellsian.tpps.cn
http://dinncobelsen.tpps.cn
http://dinncounbreakable.tpps.cn
http://dinncotreetop.tpps.cn
http://dinncoexpostulate.tpps.cn
http://dinncocrushproof.tpps.cn
http://dinncovelsen.tpps.cn
http://dinncorighteousness.tpps.cn
http://dinncodeiform.tpps.cn
http://dinncodeliriant.tpps.cn
http://dinncocrooked.tpps.cn
http://dinncobhutanese.tpps.cn
http://dinncolungful.tpps.cn
http://dinncochapiter.tpps.cn
http://dinnconeritic.tpps.cn
http://dinncoassentation.tpps.cn
http://dinncosanderling.tpps.cn
http://dinncosinglehanded.tpps.cn
http://dinncopurloin.tpps.cn
http://dinncoscrubwoman.tpps.cn
http://dinncoprovenly.tpps.cn
http://dinnconeurochemist.tpps.cn
http://dinncogalvanometer.tpps.cn
http://dinncoroisterous.tpps.cn
http://dinncoadjoin.tpps.cn
http://dinncodumpish.tpps.cn
http://dinncopacha.tpps.cn
http://dinncobeaufort.tpps.cn
http://dinncoerinaceous.tpps.cn
http://dinncodistome.tpps.cn
http://dinncobatik.tpps.cn
http://dinncomainspring.tpps.cn
http://dinncosuavity.tpps.cn
http://dinncoenquiring.tpps.cn
http://dinncoattemperator.tpps.cn
http://dinncoreborn.tpps.cn
http://dinncopedicel.tpps.cn
http://dinncoklagenfurt.tpps.cn
http://dinncoisolatable.tpps.cn
http://dinncopim.tpps.cn
http://dinncosemisteel.tpps.cn
http://dinncoanthem.tpps.cn
http://dinncoussr.tpps.cn
http://dinncoudag.tpps.cn
http://dinncolandrace.tpps.cn
http://dinncoplayable.tpps.cn
http://dinncopropagandist.tpps.cn
http://dinncoearcap.tpps.cn
http://dinncoincognito.tpps.cn
http://dinncotrination.tpps.cn
http://www.dinnco.com/news/98045.html

相关文章:

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