WEB开发网      婵犵數濮烽弫鍛婃叏閻戣棄鏋侀柛娑橈功缁犻箖鏌嶈閸撴氨鎹㈠☉娆愬闁告劕寮堕幖鎰棯閸撗勫殌闁宠鍨块幃鈺冣偓鍦Т椤ユ繈姊哄Ч鍥р偓妤呭磻閹捐桅闁告洦鍨扮粻娑㈡煕椤愶絾绀冩い搴$Ч濮婅櫣绮欏▎鎯у壋闂佸摜濮甸崝娆愪繆閻㈢ǹ绀嬫い鏍ㄨ壘閸炪劑姊洪棃娴ゆ稒鎷呴幓鎺嶅闂佸湱鍎ら〃鍡涘煕閹烘鐓曢柡鍥ュ妼娴滄粍銇勮箛锝呭籍闁哄备鈧磭鏆嗛悗锝庡墰閺嗙娀鏌ф导娆戝埌闁靛棙甯掗~婵嬫偂鎼达絼鐢荤紓浣诡殕閸ㄥ灝顫忕紒妯诲缂佹稑顑呭▓顓炩攽椤旀枻鍏紒鐘虫崌閵嗕礁顫濋幇浣光枌婵犵數濮崑鎾趁归敐鍥┿€婇柡鈧禒瀣厽婵☆垱顑欓崵瀣偓瑙勬偠閸庤精鐏冮梺缁樏鍫曞疮閻愮數纾奸柛灞炬皑鏁堥悗瑙勬礃缁繘藝鐎靛摜妫柟顖嗕礁浠悗娈垮枛閻栫厧鐣烽悡搴樻婵☆垯璀﹂悗宕囩磽閸屾瑧鍔嶆い銊ユ閻f繈骞栨担姝屾憰闂佺粯妫冮ˉ鎾诲汲鐎n喗鐓熸俊銈傚亾闁绘妫楅埢鎾澄旈崨顔规嫼闁荤姴娲犻埀顒冩珪閻忊偓闂備礁鎼幊鎰叏閹绢喗鍋╅柣銈庡灛娴滃綊鏌熼悜妯肩畺闁哄懏绻堝娲濞戞艾顣哄┑鈽嗗亝閻熲晠銆佸▎鎺旂杸闁哄啫鍊婚惁鍫ユ⒑濮瑰洤鐏叉繛浣冲嫮顩烽柨鏇炲€归悡鏇㈡煏婵炲灝鍔ら柛鈺嬬稻椤ㄣ儵鎮欓弶鎴濐潚濡ょ姷鍋為敃銏ゃ€佸▎鎾村殐闁冲搫顑囬獮銏ゆ⒒閸屾瑦绁版い顐㈩槸閻e嘲螣閼测晝鐓嬪銈嗘閿熴儲绂嶈ぐ鎺撶厵闁绘垶蓱鐏忣厼霉濠婂啰绉烘慨濠呮缁辨帒螣閾忛€涙闂備焦瀵уú宥夊疾濞戞粎浜遍梻浣告啞濞诧箓宕归柆宥呯厱闁硅揪闄勯悡娆撴煠濞村娅呭ù鐘崇矊閳规垿鍨鹃悙钘変划闂佽鍠楅〃鍛村煡婢舵劕绠抽柟鎯ь嚟瑜板洨绱撻崒娆戣窗闁哥姵鐗犻、鏍川閹碱厽鏅i梺绋跨箳閸樠呮閻愮繝绻嗘い鏍ㄧ矌鐢稒绻涢崨顓熷枠婵﹦绮幏鍛存偡闁箑娈濈紓鍌欐祰椤曆囧磹閸噮鍤曠紓浣贯缚缁♀偓闂佹悶鍎崝宥呪枍閸ヮ剚鈷戠紒瀣濠€鎵磼鐎n偅宕岀€规洏鍨介幃浠嬪川婵犲嫬骞楅梺鐟板悑閻n亪宕规繝姘厐闁哄洢鍨洪悡銉︽叏濡灝鐓愰柣鎾跺枛閻擃偊宕堕妷銉ュБ缂備礁顑堝畷鐢垫閹烘梻纾兼俊顖濆亹閻h櫣绱撴担铏瑰笡缂佽鐗嗛悾宄邦潨閳ь剚淇婂宀婃Ш缂備浇椴哥换鍫濐潖缂佹ɑ濯寸紒娑橆儏濞堟劙姊洪幖鐐插闁告鍟块悾鐑筋敍閻愯尙楠囬梺鐟邦嚟婵潧鈻撴ィ鍐┾拺缂備焦蓱閳锋帡鏌嶅畡鎵ⅵ鐎殿噮鍋婂畷鎺楁倷鐎电ǹ骞堥梻浣瑰▕閺侇噣宕戦幘缁樼厸闁告侗鍠氶幊鍛繆閸欏濮囬摶锝夋偠濞戞帒澧查柡鍌楀亾闂傚倷鑳剁划顖炲礉閺囩倣鐔哥節閸パ冩優闂佺粯鏌ㄩ惃婵嬪绩閼恒儯浜滈柡鍐ㄦ处椤ュ鏌涢弬璇测偓婵嬪箺閸洘鍊烽柣鎴炨缚閸橀亶姊洪崫鍕偍闁告柨鏈弲鍫曨敍閻愬鍘卞┑鐐叉缁绘帞绮绘繝姘厸閻忕偟鏅晥閻庤娲﹂崑濠傜暦閻旂⒈鏁嗛柍褜鍓欓埢宥夋晲閸モ晝锛濇繛杈剧稻瑜板啯绂嶉悙顒傜瘈闁靛骏绲剧涵鐐亜閹存繃宸濈紒顔剧帛閵堬綁宕橀埡鍐ㄥ箥闂佽瀛╃粙鎺戠幓鐠恒劎涓嶆慨妞诲亾闁哄被鍔岄埥澶娢熸径鐧哥稻閵囧嫰濡搁敐鍛Е闂佽鍠楅悷鈺呫€侀弮鍫濈妞ゆ挻绻勭粈鍕⒒閸屾瑦绁版い鏇熺墵瀹曚即寮介銈囶槸婵犵數濮撮崐濠氬汲閿曞倹鐓欐い鏍仜娴滅増淇婇懠棰濆殭闁宠鍨块崺鍕礃閵娧呫偡婵$偑鍊ら崢楣冨礂濡警鍤曢悹鍥ㄧゴ濡插牓鏌曡箛鏇烆潔闁冲搫鎳忛悡蹇擃熆鐠鸿櫣澧曢柛鏃€鎸抽弻娑㈠棘濞嗙偓楔缂備浇椴搁幐濠氬箯閸涱垳鐭欓幖瀛樻尭娴滈箖鏌涘┑鍕姢闁活厽鎸鹃幉鎼佹偋閸繄鐟ㄩ梺鍝勵儎缁舵岸寮婚悢鐓庣鐟滃繒鏁☉銏$厸闁告侗鍠楅崐鎰版煛鐏炶濮傞柟顔哄€濆畷鎺戔槈濮楀棔绱� ---闂傚倸鍊搁崐鎼佸磹閹间礁纾归柣鎴eГ閸婂潡鏌ㄩ弮鍫熸殰闁稿鎸剧划顓炩槈濡搫绠诲┑鐐叉▕娴滄粓鎮″☉銏$厱婵炴垵宕獮妯汇亜閺傛寧顥㈡慨濠呮閹瑰嫰濡搁妷锔惧綒闂備胶鎳撻崵鏍箯閿燂拷
开发学院软件开发C++ C语言库函数(P类字母) 阅读

C语言库函数(P类字母)

 2008-03-08 12:31:03 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾瑰瀣椤愯姤鎱ㄥ鍡楀幊缂傚倹姘ㄩ幉绋款吋閸澀缃曢梻鍌欑濠€閬嶆惞鎼淬劌绐楅柡宥庡亞娑撳秵銇勯弽顐沪闁绘挶鍎甸弻锝夊即閻愭祴鍋撻崷顓涘亾濮樼偓瀚�闂傚倸鍊搁崐鎼佸磹閹间礁纾瑰瀣捣閻棗銆掑锝呬壕濡ょ姷鍋涢ˇ鐢稿极閹剧粯鍋愰柟缁樺笧閳ь剦鍙冨鍝勑ч崶褏浠奸梺璇茬箲閼归箖鎮鹃悜钘夎摕闁靛濡囬崢鐢告⒑鐟欏嫷鍟忛柛鐘崇墵閵嗗倹绺介崨濠勫幈闁硅壈鎻槐鏇熺墡闂備線娼уú銈団偓姘嵆閻涱噣骞掑Δ鈧粻锝嗙節闂堟稑鏆欏ù婊堢畺閺岋綁濮€閳惰泛婀辨竟鏇熺節濮橆厾鍘甸梺缁樺姦閸撴岸鎮樻潏銊ょ箚闁圭粯甯炴晶娑氱磼缂佹ḿ娲寸€规洖宕灃闁告劕鍟犻崜婵堟崲濞戞ḿ鏆嗗┑鐘辫兌閺佹牜绱撴担浠嬪摵闁圭懓娲ら悾鐑藉箳閹搭厽鍍甸梺鐟板悁閻掞箓鎮楅幖浣光拻濞达絿鍎ら崵鈧梺鎼炲€栭悧鐘荤嵁韫囨稒鏅搁柨鐕傛嫹婵犵數濮烽弫鍛婃叏閻戣棄鏋侀柛娑橈攻閸欏繑銇勯幘鍗炵仼缂佺媭鍨堕弻娑㈠箛闂堟稒鐏堥悗鐟版啞缁诲啴濡甸崟顖氱閻庨潧鎽滈悾濂告⒑绾拋娼愭繛鑼枎椤繒绱掑Ο鑲╂嚌闂侀€炲苯澧畝锝堝劵椤︽煡鎮¢妶澶嬬厪闁割偅绻冮崑顏呯箾瀹割喕绨婚幆鐔兼⒑鐎圭姵銆冮柤鍐茬埣瀹曟繈鏁冮埀顒勨€旈崘顔嘉ч柛鈩冾殘閻熸劙姊洪悡搴℃毐闁绘牕銈稿畷鐑樼節閸パ冨祮闂侀潧楠忕槐鏇㈠储椤忓牊鈷戦柟鑲╁仜閸旀鏌¢崨顔锯姇缂佸倹甯熼ˇ瀵哥磼鏉堛劌绗氭繛鐓庣箻閸┾剝鎷呴柨瀣垫綗闂傚倷娴囧銊╂倿閿曞倸绠查柛銉墮閺嬩線鏌熼崜褏甯涢柡鍛倐閺屻劑鎮ら崒娑橆伓闂傚倸鍊搁崐鎼佸磹閹间礁纾瑰瀣椤愯姤鎱ㄥ鍡楀幊缂傚倹姘ㄩ幉绋款吋閸澀缃曢梻鍌欑濠€閬嶆惞鎼淬劌绐楅柡宥庡亞娑撳秵銇勯弽顐沪闁绘挶鍎甸弻锝夊即閻愭祴鍋撻崷顓涘亾濮樼偓瀚�  闂傚倸鍊搁崐鎼佸磹閹间礁纾归柣鎴eГ閸ゅ嫰鏌ら崫銉︽毄濞寸姵姘ㄧ槐鎾诲磼濞嗘帒鍘$紓渚囧櫘閸ㄥ爼濡撮崘顔煎窛闁哄鍨归崢娲倵楠炲灝鍔氭い锔诲灦瀹曪繝骞庨懞銉у帾闂婎偄娲﹀ú鏍ㄧ墡闂備浇顕х€垫帡宕滈悢濂夋綎闁惧繐婀辩壕鍏间繆椤栨碍鎯堟い顐㈢焸濮婃椽宕烽娑欏珱闂佺ǹ顑呭Λ婵嬪箚閳ь剚銇勮箛鎾寸ォ婵☆垰瀚板娲传閸曨剚鎷卞┑鐐插级宀e潡骞戦姀鐘斀濠电姴瀚弶鎼佹⒑閸濆嫭宸濆┑顔惧厴閹即濡烽埡鍌楁嫽婵炶揪绲介幖顐ゆ暜鐠轰警鐔嗛柣鐔峰簻閺€鑽ょ磼閸屾氨孝妤楊亙鍗冲畷鐓庮潩閿濆懍澹曢梺鍝勫暙閻楀棛绮堥崘鈹夸簻闊洤娴烽ˇ锕€霉濠婂牏鐣洪柡灞诲妼閳规垿宕卞☉鎵佸亾濡も偓椤儻顧侀柛鐘崇墵濠€渚€姊虹紒妯曟垿鎮烽妷褉鍋撳鐓庢灓缂侇喚绮妶锝夊礃閳哄啫骞堟俊鐐€栭崝鎴﹀磹閺囥垹鍑犻幖娣妽閻撶喖鐓崶褜鍎忛柛鏃€绮撻弻鏇㈠炊瑜嶉顓犫偓娈垮枟濞兼瑨鐏掗梺鍛婄箓鐎氼剝顤傛繝纰夌磿閸嬫垿宕愰幋锕€鍨傛繛宸簼閸嬶繝鏌嶉崫鍕櫣缂佺姵鐗犻弻宥夊煛娴e憡娈查梺绋挎捣閸犳牠寮婚弴銏犵倞鐟滃秶鑺辨繝姘厵闁告垯鍊栫€氾拷
核心提示: 函数名: parsfnm 功能: 分析文件名 用法: char *parsfnm (char *cmdline, strUCt fcb *fcbptr, int option); 程序例: #include <PRocess.h> #include <string.h> #include &l
   
函数名: parsfnm 
功 能: 分析文件名 
用 法: char *parsfnm (char *cmdline, strUCt fcb *fcbptr, int option); 
程序例: 

#include <PRocess.h> 
#include <string.h> 
#include <stdio.h> 
#include <dos.h> 

int main(void) 

  char line[80]; 
  struct fcb blk; 

  /* get file name */ 
  printf("Enter drive and file name (no path - ie. a:file.dat)\n"); 
  gets(line); 

  /* put file name in fcb */ 
  if (parsfnm(line, &blk, 1) == NULL) 
   printf("Error in parsfm call\n"); 
  else 
   printf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name); 

  return 0; 

 
 

函数名: peek 
功 能: 检查存储单元 
用 法: int peek(int segment, unsigned offset); 
程序例: 

#include <stdio.h> 
#include <conio.h> 
#include <dos.h> 

int main(void) 

  int value = 0; 

  printf("The current status of your keyboard is:\n"); 
  value = peek(0x0040, 0x0017); 
  if (value & 1) 
   printf("Right shift on\n"); 
  else 
   printf("Right shift off\n"); 

  if (value & 2) 
   printf("Left shift on\n"); 
  else 
   printf("Left shift off\n"); 

  if (value & 4) 
   printf("Control key on\n"); 
  else 

   printf("Control key off\n"); 

  if (value & 8) 
   printf("Alt key on\n"); 
  else 
   printf("Alt key off\n"); 

  if (value & 16) 
   printf("Scroll lock on\n"); 
  else 
   printf("Scroll lock off\n"); 

  if (value & 32) 
   printf("Num lock on\n"); 
  else 
   printf("Num lock off\n"); 

  if (value & 64) 
   printf("Caps lock on\n"); 
  else 
   printf("Caps lock off\n"); 

  return 0; 

 
 

函数名: peekb 
功 能: 检查存储单元 
用 法: char peekb (int segment, unsigned offset); 
程序例: 

#include <stdio.h> 
#include <conio.h> 
#include <dos.h> 

int main(void) 

  int value = 0; 

  printf("The current status of your keyboard is:\n"); 
  value = peekb(0x0040, 0x0017); 
  if (value & 1) 
   printf("Right shift on\n"); 
  else 
   printf("Right shift off\n"); 

  if (value & 2) 
   printf("Left shift on\n"); 
  else 
   printf("Left shift off\n"); 

  if (value & 4) 
   printf("Control key on\n"); 
  else 
   printf("Control key off\n"); 

  if (value & 8) 
   printf("Alt key on\n"); 
  else 
   printf("Alt key off\n"); 


  if (value & 16) 
   printf("Scroll lock on\n"); 
  else 
   printf("Scroll lock off\n"); 

  if (value & 32) 
   printf("Num lock on\n"); 
  else 
   printf("Num lock off\n"); 

  if (value & 64) 
   printf("Caps lock on\n"); 
  else 
   printf("Caps lock off\n"); 

  return 0; 

 
 

函数名: perror 
功 能: 系统错误信息 
用 法: void perror(char *string); 
程序例: 

#include <stdio.h> 

int main(void) 

  FILE *fp; 

  fp = fopen("perror.dat", "r"); 
  if (!fp) 
   perror("Unable to open file for reading"); 
  return 0; 

 
 

函数名: pieslice 
功 能: 绘制并填充一个扇形 
用 法: void far pieslice(int x, int stanle, int endangle, int radius); 
程序例: 

#include <graphics.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 

int main(void) 

  /* request auto detection */ 
  int gdriver = DETECT, gmode, errorcode; 
  int midx, midy; 
  int stangle = 45, endangle = 135, radius = 100; 

  /* initialize graphics and local variables */ 
  initgraph(&gdriver, &gmode, ""); 

  /* read result of initialization */ 
  errorcode = graphresult(); 
  if (errorcode != grOk) /* an error occurred */ 
  { 
   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 

   printf("Press any key to halt:"); 
   getch(); 
   exit(1); /* terminate with an error code */ 
  } 

  midx = getmaxx() / 2; 
  midy = getmaxy() / 2; 

  /* set fill style and draw a pie slice */ 
  setfillstyle(EMPTY_FILL, getmaxcolor()); 
  pieslice(midx, midy, stangle, endangle, radius); 

  /* clean up */ 
  getch(); 
  closegraph(); 
  return 0; 

 
 

函数名: poke 
功 能: 存值到一个给定存储单元 
用 法: void poke(int segment, int offset, int value); 
程序例: 

#include <dos.h> 
#include <conio.h> 

int main(void) 

  clrscr(); 
  cprintf("Make sure the scroll lock key is off and press any key\r\n"); 
  getch(); 
  poke(0x0000,0x0417,16); 
  cprintf("The scroll lock is now on\r\n"); 
  return 0; 

 
 

函数名: pokeb 
功 能: 存值到一个给定存储单元 
用 法: void pokeb(int segment, int offset, char value); 
程序例: 

#include <dos.h> 
#include <conio.h> 

int main(void) 

  clrscr(); 
  cprintf("Make sure the scroll lock key is off and press any key\r\n"); 
  getch(); 
  pokeb(0x0000,0x0417,16); 
  cprintf("The scroll lock is now on\r\n"); 
  return 0; 

 
 

函数名: poly 
功 能: 根据参数产生一个多项式 
用 法: double poly(double x, int n, double c[]); 
程序例: 

#include <stdio.h> 
#include <math.h> 


/* polynomial: x**3 - 2x**2 + 5x - 1 */ 

int main(void) 

  double array[] = { -1.0, 5.0, -2.0, 1.0 }; 
  double result; 

  result = poly(2.0, 3, array); 
  printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n", 
      result); 
  return 0; 

 
 

函数名: pow 
功 能: 指数函数(x的y次方) 
用 法: double pow(double x, double y); 
程序例: 

#include <math.h> 
#include <stdio.h> 

int main(void) 

  double x = 2.0, y = 3.0; 

  printf("%lf raised to %lf is %lf\n", x, y, pow(x, y)); 
  return 0; 

 

函数名: pow10 
功 能: 指数函数(10的p次方) 
用 法: double pow10(int p); 
程序例: 

#include <math.h> 
#include <stdio.h> 

int main(void) 

  double p = 3.0; 

  printf("Ten raised to %lf is %lf\n", p, pow10(p)); 
  return 0; 

 
 

函数名: printf 
功 能: 产生格式化输出的函数 
用 法: int printf(char *format...); 
程序例: 

#include <stdio.h> 
#include <string.h> 

#define I 555 
#define R 5.5 

int main(void) 

  int i,j,k,l; 
  char buf[7]; 
  char *prefix = buf; 
  char tp[20]; 
  printf("prefix 6d   6o   8x    10.2e    " 
     "10.2f\n"); 
  strcpy(prefix,"%"); 

  for (i = 0; i < 2; i++) 
  { 
   for (j = 0; j < 2; j++) 
     for (k = 0; k < 2; k++) 
   for (l = 0; l < 2; l++) 
      { 
        if (i==0) strcat(prefix,"-"); 
        if (j==0) strcat(prefix,"+"); 
        if (k==0) strcat(prefix,"#"); 
        if (l==0) strcat(prefix,"0"); 
        printf("%5s ",prefix); 
        strcpy(tp,prefix); 
        strcat(tp,"6d "); 
        printf(tp,I); 
        strcpy(tp,""); 
        strcpy(tp,prefix); 
        strcat(tp,"6o "); 
        printf(tp,I); 
        strcpy(tp,""); 
        strcpy(tp,prefix); 
        strcat(tp,"8x "); 
        printf(tp,I); 
        strcpy(tp,""); 
        strcpy(tp,prefix); 
    strcat(tp,"10.2e "); 
    printf(tp,R); 

    strcpy(tp,prefix); 
    strcat(tp,"10.2f "); 
    printf(tp,R); 
    printf(" \n"); 
    strcpy(prefix,"%"); 
   } 
    } 
  return 0; 

 
 

函数名: putc 
功 能: 输出一字符到指定流中 
用 法: int putc(int ch, FILE *stream); 
程序例: 

#include <stdio.h> 

int main(void) 

  char msg[] = "Hello world\n"; 
  int i = 0; 

  while (msg[i]) 
   putc(msg[i++], stdout); 
  return 0; 

 
 

函数名: putch 
功 能: 输出字符到控制台 
用 法: int putch(int ch); 
程序例: 

#include <stdio.h> 
#include <conio.h> 

int main(void) 

  char ch = 0; 

  printf("Input a string:"); 
  while ((ch != '\r')) 
  { 
   ch = getch(); 
   putch(ch); 
  } 
  return 0; 

 
 

函数名: putchar 
功 能: 在stdout上输出字符 
用 法: int putchar(int ch); 
程序例: 

#include <stdio.h> 

/* define some box-drawing characters */ 
#define LEFT_TOP 0xDA 
#define RIGHT_TOP 0xBF 
#define HORIZ   0xC4 
#define VERT   0xB3 
#define LEFT_BOT 0xC0 
#define RIGHT_BOT 0xD9 

int main(void) 

  char i, j; 

  /* draw the top of the box */ 
  putchar(LEFT_TOP); 
  for (i=0; i<10; i++) 

   putchar(HORIZ); 
  putchar(RIGHT_TOP); 
  putchar('\n'); 

  /* draw the middle */ 
  for (i=0; i<4; i++) 
  { 
   putchar(VERT); 
   for (j=0; j<10; j++) 
     putchar(' '); 
   putchar(VERT); 
   putchar('\n'); 
  } 

  /* draw the bottom */ 
  putchar(LEFT_BOT); 
  for (i=0; i<10; i++) 
   putchar(HORIZ); 
  putchar(RIGHT_BOT); 
  putchar('\n'); 

  return 0; 

 
 

函数名: putenv 
功 能: 把字符串加到当前环境中 
用 法: int putenv(char *envvar); 
程序例: 

#include <stdio.h> 
#include <stdlib.h> 
#include <alloc.h> 
#include <string.h> 
#include <dos.h> 

int main(void) 

  char *path, *ptr; 
  int i = 0; 

  /* get the current path environment */ 
  ptr = getenv("PATH"); 

  /* set up new path */ 
  path = malloc(strlen(ptr)+15); 
  strcpy(path,"PATH="); 
  strcat(path,ptr); 
  strcat(path,";c:\\temp"); 

  /* replace the current path and display current environment */ 
  putenv(path); 
  while (environ[i]) 
    printf("%s\n",environ[i++]); 

  return 0; 

 
 

函数名: putimage 
功 能: 在屏幕上输出一个位图 
用 法: void far putimage(int x, int y, void far *bitmap, int op); 
程序例: 

#include <graphics.h> 

#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 

#define ARROW_SIZE 10 

void draw_arrow(int x, int y); 

int main(void) 

  /* request autodetection */ 
  int gdriver = DETECT, gmode, errorcode; 
  void *arrow; 
  int x, y, maxx; 
  unsigned int size; 

  /* initialize graphics and local variables */ 
  initgraph(&gdriver, &gmode, ""); 

  /* read result of initialization */ 
  errorcode = graphresult(); 
  if (errorcode != grOk) /* an error occurred */ 
  { 
   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
   printf("Press any key to halt:"); 
   getch(); 
   exit(1); /* terminate with an error code */ 
  } 

  maxx = getmaxx(); 
  x = 0; 
  y = getmaxy() / 2; 

  /* draw the image to be grabbed */ 
  draw_arrow(x, y); 

  /* calculate the size of the image */ 
  size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); 

  /* allocate memory to hold the image */ 
  arrow = malloc(size); 

  /* grab the image */ 
  getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); 

  /* repeat until a key is pressed */ 
  while (!kbhit()) 
  { 
   /* erase old image */ 
   putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); 

   x += ARROW_SIZE; 

   if (x >= maxx) 
     x = 0; 

   /* plot new image */ 
   putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); 
  } 

  /* clean up */ 
  free(arrow); 
  closegraph(); 
  return 0; 


void draw_arrow(int x, int y) 

  /* draw an arrow on the screen */ 
  moveto(x, y); 
  linerel(4*ARROW_SIZE, 0); 
  linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); 
  linerel(0, 2*ARROW_SIZE); 
  linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 

 
 

函数名: putpixel 
功 能: 在指定位置画一像素 
用 法: void far putpixel (int x, int y, int pixelcolor); 
程序例: 

#include <graphics.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 
#include <dos.h> 

#define PIXEL_COUNT 1000 
#define DELAY_TIME 100 /* in milliseconds */ 

int main(void) 

  /* request autodetection */ 
  int gdriver = DETECT, gmode, errorcode; 
  int i, x, y, color, maxx, maxy, maxcolor, seed; 

  /* initialize graphics and local variables */ 
  initgraph(&gdriver, &gmode, ""); 

  /* read result of initialization */ 
  errorcode = graphresult(); 
  if (errorcode != grOk) /* an error occurred */ 
  { 
   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
   printf("Press any key to halt:"); 
   getch(); 
   exit(1); /* terminate with an error code */ 

  } 

  maxx = getmaxx() + 1; 
  maxy = getmaxy() + 1; 
  maxcolor = getmaxcolor() + 1; 

  while (!kbhit()) 
  { 
   /* seed the random number generator */ 
   seed = random(32767); 
   srand(seed); 
   for (i=0; i<PIXEL_COUNT; i++) 
   { 
 x = random(maxx); 
     y = random(maxy); 
     color = random(maxcolor); 
     putpixel(x, y, color); 
   } 

   delay(DELAY_TIME); 
   srand(seed); 
   for (i=0; i<PIXEL_COUNT; i++) 
   { 
 x = random(maxx); 
 y = random(maxy); 
 color = random(maxcolor); 
 if (color == getpixel(x, y)) 
   putpixel(x, y, 0); 
   } 
  } 

  /* clean up */ 
  getch(); 
  closegraph(); 
  return 0; 

 
 

函数名: puts 
功 能: 送一字符串到流中 
用 法: int puts(char *string); 
程序例: 

#include <stdio.h> 
int main(void) 

  char string[] = "This is an example output string\n"; 

  puts(string); 
  return 0; 

 
 

函数名: puttext 
功 能: 将文本从存储区拷贝到屏幕 
用 法: int puttext(int left, int top, int right, int bottom, void *source); 
程序例: 

#include <conio.h> 
int main(void) 


  char buffer[512]; 

  /* put some text to the console */ 
  clrscr(); 
  gotoxy(20, 12); 
  cprintf("This is a test. Press any key to continue ..."); 
  getch(); 

  /* grab screen contents */ 
  gettext(20, 12, 36, 21,buffer); 
  clrscr(); 

  /* put selected characters back to the screen */ 
  gotoxy(20, 12); 
  puttext(20, 12, 36, 21, buffer); 
  getch(); 

  return 0; 

 
 

函数名: putw 
功 能: 把一字符或字送到流中 
用 法: int putw(int w, FILE *stream); 
程序例: 

#include <stdio.h> 
#include <stdlib.h> 

#define FNAME "test.$$$" 

int main(void) 

  FILE *fp; 
  int Word; 

  /* place the word in a file */ 
  fp = fopen(FNAME, "wb"); 
  if (fp == NULL) 
  { 
   printf("Error opening file %s\n", FNAME); 
   exit(1); 
  } 

  word = 94; 
  putw(word,fp); 
  if (ferror(fp)) 
    printf("Error writing to file\n"); 
  else 
    printf("Successful write\n"); 
  fclose(fp); 

  /* reopen the file */ 
  fp = fopen(FNAME, "rb"); 
  if (fp == NULL) 
  { 
   printf("Error opening file %s\n", FNAME); 
   exit(1); 
  } 

  /* extract the word */ 

  word = getw(fp); 
  if (ferror(fp)) 
    printf("Error reading file\n"); 
  else 
    printf("Successful read: word = %d\n", word); 

  /* clean up */ 
  fclose(fp); 
  unlink(FNAME); 

  return 0; 

Tags:语言 函数 字母

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接