C语言函数大全(r开头).doc_第1页
C语言函数大全(r开头).doc_第2页
C语言函数大全(r开头).doc_第3页
C语言函数大全(r开头).doc_第4页
C语言函数大全(r开头).doc_第5页
已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论