




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机科学与技术社区CSTC团队资料组制作函数大全(r开头)61函数名:raise 功能:向正在执行的程序发送一个信号 用法:intraise(intsig); 程序例: #include intmain(void) inta,b; a=10; b=0; if(b=0) /*preemptdividebyzeroerror*/ raise(SIGFPE); a=a/b; return0; 函数名:rand 功能:随机数发生器 用法:voidrand(void); 程序例: #include #include intmain(void) inti; printf(Tenrandomnumbersfrom0to99nn); for(i=0;i10;i+) printf(%dn,rand()%100); return0; 函数名:randbrd 功能:随机块读 用法:intrandbrd(structfcb*fcbptr,intreccnt); 程序例: #include #include #include #include intmain(void) charfar*save_dta; charline80,buffer256; structfcbblk; inti,result; /*getuserinputfilenamefordta*/ printf(Enterdriveandfilename(nopath-i.e.a:file.dat)n); gets(line); /*putfilenameinfcb*/ if(!parsfnm(line,&blk,1) printf(Errorincalltoparsfnmn); exit(1); printf(Drive#%dFile:%snn,blk.fcb_drive,blk.fcb_name); /*openfilewithDOSFCBopenfile*/ bdosptr(0x0F,&blk,0); /*saveolddta,andsetnewone*/ save_dta=getdta(); setdta(buffer); /*setupinfoforthenewdta*/ blk.fcb_recsize=128; blk.fcb_random=0L; result=randbrd(&blk,1); /*checkresultsfromrandbrd*/ if(!result) printf(ReadOKnn); else perror(Errorduringread); exit(1); /*readindatafromthenewdta*/ printf(Thefirst128charactersare:n); for(i=0;i128;i+) putchar(bufferi); /*restorepreviousdta*/ setdta(save_dta); return0; 函数名:randbwr 功能:随机块写 用法:intrandbwr(structfcp*fcbptr,intreccnt); 程序例: #include #include #include #include intmain(void) charfar*save_dta; charline80; charbuffer256=RANDBWRtest!; structfcbblk; intresult; /*getnewfilenamefromuser*/ printf(Enterafilenametocreate(nopath-ie.a:file.datn); gets(line); /*parsethenewfilenametothedta*/ parsfnm(line,&blk,1); printf(Drive#%dFile:%sn,blk.fcb_drive,blk.fcb_name); /*requestDOSservicestocreatefile*/ if(bdosptr(0x16,&blk,0)=-1) perror(Errorcreatingfile); exit(1); /*saveolddtaandsetnewdta*/ save_dta=getdta(); setdta(buffer); /*writenewrecords*/ blk.fcb_recsize=256; blk.fcb_random=0L; result=randbwr(&blk,1); if(!result) printf(WriteOKn); else perror(Diskerror); exit(1); /*requestDOSservicestoclosethefile*/ if(bdosptr(0x10,&blk,0)=-1) perror(Errorclosingfile); exit(1); /*resettheolddta*/ setdta(save_dta); return0; 函数名:random 功能:随机数发生器 用法:intrandom(intnum); 程序例: #include #include #include /*printsarandomnumberintherange0to99*/ intmain(void) randomize(); printf(Randomnumberinthe0-99range:%dn,random(100); return0; 函数名:randomize 功能:初始化随机数发生器 用法:voidrandomize(void); 程序例: #include #include #include intmain(void) inti; randomize(); printf(Tenrandomnumbersfrom0to99nn); for(i=0;i10;i+) printf(%dn,rand()%100); return0; 函数名:read 功能:从文件中读 用法:intread(inthandle,void*buf,intnbyte); 程序例: #include #include #include #include #include #include intmain(void) void*buf; inthandle,bytes; buf=malloc(10); /* LooksforafileinthecurrentdirectorynamedTEST.$andattempts toread10bytesfromit.Tousethisexampleyoushouldcreatethe fileTEST.$ */ if(handle= open(TEST.$,O_RDONLY|O_BINARY,S_IWRITE|S_IREAD)=-1) printf(ErrorOpeningFilen); exit(1); if(bytes=read(handle,buf,10)=-1) printf(ReadFailed.n); exit(1); else printf(Read:%dbytesread.n,bytes); return0; 函数名:realloc 功能:重新分配主存 用法:void*realloc(void*ptr,unsignednewsize); 程序例: #include #include #include intmain(void) char*str; /*allocatememoryforstring*/ str=malloc(10); /*copyHellointostring*/ strcpy(str,Hello); printf(Stringis%snAddressis%pn,str,str); str=realloc(str,20); printf(Stringis%snNewaddressis%pn,str,str); /*freememory*/ free(str); return0; 函数名:rectangle 功能:画一个矩形 用法:voidfarrectangle(intleft,inttop,intright,intbottom); 程序例: #include #include #include #include intmain(void) /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; intleft,top,right,bottom; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode!=grOk)/*anerroroccurred*/ printf(Graphicserror:%sn,grapherrormsg(errorcode); printf(Pressanykeytohalt:); getch(); exit(1);/*terminatewithanerrorcode*/ left=getmaxx()/2-50; top=getmaxy()/2-50; right=getmaxx()/2+50; bottom=getmaxy()/2+50; /*drawarectangle*/ rectangle(left,top,right,bottom); /*cleanup*/ getch(); closegraph(); return0; 函数名:registerbgidriver 功能:登录已连接进来的图形驱动程序代码 用法:intregisterbgidriver(void(*driver)(void); 程序例: #include #include #include #include intmain(void) /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; /*registeradriverthatwasaddedintographics.lib*/ errorcode=registerbgidriver(EGAVGA_driver); /*reportanyregistrationerrors*/ if(errorcode0) printf(Graphicserror:%sn,grapherrormsg(errorcode); printf(Pressanykeytohalt:); getch(); exit(1);/*terminatewithanerrorcode*/ /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode!=grOk)/*anerroroccurred*/ printf(Graphicserror:%sn,grapherrormsg(errorcode); printf(Pressanykeytohalt:); getch(); exit(1);/*terminatewithanerrorcode*/ /*drawaline*/ line(0,0,getmaxx(),getmaxy(); /*cleanup*/ getch(); closegraph(); return0; 函数名:remove 功能:删除一个文件 用法:intremove(char*filename); 程序例: #include intmain(void) charfile80; /*promptforfilenametodelete*/ printf(Filetodelete:); gets(file); /*deletethefile*/ if(remove(file)=0) printf(Removed%s.n,file); else perror(remove); return0; 函数名:rename 功能:重命名文件 用法:intrename(char*oldname,char*newname); 程序例: #include intmain(void) charoldname80,newname80; /*promptforfiletorenameandnewname*/ printf(Filetorename:); gets(oldname); printf(Newname:); gets(newname); /*Renamethefile*/ if(rename(oldname,newname)=0) printf(Renamed%sto%s.n,oldname,newname); else perror(rename); return0; 函数名:restorecrtmode 功能:将屏幕模式恢复为先前的imitgraph设置 用法:voidfarrestorecrtmode(void); 程序例: #include #include #include #include intmain(void) /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; intx,y; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode!=grOk)/*anerroroccurred*/ printf(Graphicserror:%sn,grapherrormsg(errorcode); printf(Pressanykeytohalt:); getch(); exit(1);/*terminatewithanerrorcode*/ x=getmaxx()/2; y=getmaxy()/2; /*outputamessage*/ settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(x,y,Pressanykeytoexitgraphics:); getch(); /*restoresystemtotextmode*/ restorecrtmode(); printf(Werenowintextmode.n); printf(Pressanykeytoreturntographicsmode:); getch(); /*returntographicsmode*/ setgraphmode(getgraphmode(); /*outputamessage*/ settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(x,y,Werebackingraphicsmode.); outtextxy(x,y+textheight(W),Pressanykeytohalt:); /*cleanup*/ getch(); closegraph(); return0; 函数名:rewind 功能:将文件指针重新指向一个流的开头 用法:intrewind(FILE*stream); 程序例: #include #
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 入职新员工安全培训课件
- 倾斜试验课件
- 伸缩警棍的使用课件
- 传菜部基本培训知识课件
- 2025年鄂州市重点中学物理高三第一学期期末学业质量监测试题
- 青浦区企业管理办法
- 企业班组安全培训
- 纪检巡查人员管理办法
- 期门穴对失眠的即时效应-洞察及研究
- 2025特许经营加盟店合同协议书模板
- 押题宝典期货从业资格之《期货法律法规》试题及参考答案详解(能力提升)
- 无人机驾驶培训专业知识课件
- 2025年北师大版新教材数学二年级上册教学计划(含进度表)
- 初中语文学科组质量分析
- 70岁老年人三力测试能力考试题库及答案
- 2025年职业指导师(中级)考试全真模拟试卷
- 2025年广告设计师专业知识考核试卷:2025年广告设计与制作软件应用实战试题
- 供应商保价协议合同范本
- 2025-2030中国乒乓发球机行业市场运营模式及未来发展动向预测报告
- 在线知识付费讲座创新创业项目商业计划书
- GB 2536-2025电工流体变压器和开关用的未使用过的矿物绝缘油
评论
0/150
提交评论