⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 王大刚--c语言编程宝典--s.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; struct date reset; 
      <BR>&nbsp;&nbsp; struct date save_date; <BR>
      <P>&nbsp;&nbsp; getdate(&amp;save_date); <BR>&nbsp;&nbsp; printf("Original 
      date:\n"); <BR>&nbsp;&nbsp; system("date"); <BR>
      <P>&nbsp;&nbsp; reset.da_year = 2001; <BR>&nbsp;&nbsp; reset.da_day = 1; 
      <BR>&nbsp;&nbsp; reset.da_mon = 1; <BR>&nbsp;&nbsp; setdate(&amp;reset); 
      <BR>
      <P>&nbsp;&nbsp; printf("Date after setting:\n"); <BR>&nbsp;&nbsp; 
      system("date"); <BR>
      <P>&nbsp;&nbsp; setdate(&amp;save_date); <BR>&nbsp;&nbsp; printf("Back to 
      original date:\n"); <BR>&nbsp;&nbsp; system("date"); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setdisk <BR>功&nbsp; 能: 设置当前磁盘驱动器 <BR>用&nbsp; 法: int setdisk(int 
      drive); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dir.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int save, disk, disks; <BR>
      <P>&nbsp;&nbsp; /* save original drive */ <BR>&nbsp;&nbsp; save = 
      getdisk(); <BR>
      <P>&nbsp;&nbsp; /* print number of logic drives */ <BR>&nbsp;&nbsp; disks 
      = setdisk(save); <BR>&nbsp;&nbsp; printf("%d logical drives on the 
      system\n\n", disks); <BR>
      <P>&nbsp;&nbsp; /* print the drive letters available */ <BR>&nbsp;&nbsp; 
      printf("Available drives:\n"); <BR>&nbsp;&nbsp; for (disk = 0;disk &lt; 
      26;++disk) <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      setdisk(disk); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (disk == getdisk()) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%c: drive is 
      available\n", disk + 'a'); <BR>&nbsp;&nbsp; } <BR>&nbsp;&nbsp; 
      setdisk(save); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setdta <BR>功&nbsp; 能: 设置磁盘传输区地址 <BR>用&nbsp; 法: void setdta(char 
      far *dta); <BR>程序例: <BR>
      <P>#include &lt;process.h&gt; <BR>#include &lt;string.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char line[80], far *save_dta; 
      <BR>&nbsp;&nbsp; char buffer[256] = "SETDTA test!"; <BR>&nbsp;&nbsp; 
      struct fcb blk; <BR>&nbsp;&nbsp; int result; <BR>
      <P>&nbsp;&nbsp; /* get new file name from user */ <BR>&nbsp;&nbsp; 
      printf("Enter a file name to create:"); <BR>&nbsp;&nbsp; gets(line); <BR>
      <P>&nbsp;&nbsp; /* parse the new file name to the dta */ <BR>&nbsp;&nbsp; 
      parsfnm(line, &amp;blk, 1); <BR>&nbsp;&nbsp; printf("%d %s\n", 
      blk.fcb_drive, blk.fcb_name); <BR>
      <P>&nbsp;&nbsp; /* request DOS services to create file */ <BR>&nbsp;&nbsp; 
      if (bdosptr(0x16, &amp;blk, 0) == -1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error creating file"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* save old dta and set new dta */ <BR>&nbsp;&nbsp; 
      save_dta = getdta(); <BR>&nbsp;&nbsp; setdta(buffer); <BR>
      <P>&nbsp;&nbsp; /* write new records */ <BR>&nbsp;&nbsp; blk.fcb_recsize = 
      256; <BR>&nbsp;&nbsp; blk.fcb_random = 0L; <BR>&nbsp;&nbsp; result = 
      randbwr(&amp;blk, 1); <BR>&nbsp;&nbsp; printf("result = %d\n", result); 
      <BR>
      <P>&nbsp;&nbsp; if (!result) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Write OK\n"); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Disk error"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* request DOS services to close the file */ 
      <BR>&nbsp;&nbsp; if (bdosptr(0x10, &amp;blk, 0) == -1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error closing file"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* reset the old dta */ <BR>&nbsp;&nbsp; setdta(save_dta); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setfillpattern <BR>功&nbsp; 能: 选择用户定义的填充模式 <BR>用&nbsp; 法: void far 
      setfillpattern(char far *upattern, int color); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int maxx, maxy; <BR>
      <P>&nbsp;&nbsp; /* a user defined fill pattern */ <BR>&nbsp;&nbsp; char 
      pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; 
      /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      grapherrormsg(errorcode)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Press any key to halt:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      getch(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an 
      error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; maxx = getmaxx(); <BR>&nbsp;&nbsp; maxy = getmaxy(); 
      <BR>&nbsp;&nbsp; setcolor(getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* select a user defined fill pattern */ <BR>&nbsp;&nbsp; 
      setfillpattern(pattern, getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* fill the screen with the pattern */ <BR>&nbsp;&nbsp; 
      bar(0, 0, maxx, maxy); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setfillstyle <BR>功&nbsp; 能: 设置填充模式和颜色 <BR>用&nbsp; 法: void far 
      setfillstyle(int pattern, int color); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;string.h&gt; <BR>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; 
      <BR>
      <P>/* the names of the fill styles supported */ <BR>char *fname[] = { 
      "EMPTY_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "SOLID_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "LINE_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "LTSLASH_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "SLASH_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "BKSLASH_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "LTBKSLASH_FILL", <BR>&nbsp;&nbsp;&nbsp; "HATCH_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "XHATCH_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "INTERLEAVE_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "WIDE_DOT_FILL", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "CLOSE_DOT_FILL", <BR>&nbsp;&nbsp;&nbsp; "USER_FILL" 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      }; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int style, midx, midy; <BR>&nbsp;&nbsp; char stylestr[40]; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; 
      /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      grapherrormsg(errorcode)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Press any key to halt:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      getch(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an 
      error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>
      <P>&nbsp;&nbsp; for (style = EMPTY_FILL; style &lt; USER_FILL; style++) 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* select the fill 
      style */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(style, 
      getmaxcolor()); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* convert style into a string */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(stylestr, fname[style]); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* fill a bar */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bar3d(0, 0, midx-10, midy, 0, 0); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* output a message */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(midx, midy, stylestr); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* wait for a key */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleardevice(); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setftime <BR>功&nbsp; 能: 设置文件日期和时间 <BR>用&nbsp; 法: int setftime(int 
      handle, struct ftime *ftimep); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;process.h&gt; <BR>#include 
      &lt;fcntl.h&gt; <BR>#include &lt;io.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; struct ftime filet; 
      <BR>&nbsp;&nbsp; FILE *fp; <BR>
      <P>&nbsp;&nbsp; if ((fp = fopen("TEST.$$$", "w")) == NULL) 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error:"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; fprintf(fp, "testing...\n"); <BR>
      <P>&nbsp;&nbsp; /* load ftime structure with new time and date */ 
      <BR>&nbsp;&nbsp; filet.ft_tsec = 1; <BR>&nbsp;&nbsp; filet.ft_min = 1; 
      <BR>&nbsp;&nbsp; filet.ft_hour = 1; <BR>&nbsp;&nbsp; filet.ft_day = 1; 
      <BR>&nbsp;&nbsp; filet.ft_month = 1; <BR>&nbsp;&nbsp; filet.ft_year = 21; 
      <BR>
      <P>&nbsp;&nbsp; /* show current directory for time and date */ 
      <BR>&nbsp;&nbsp; system("dir TEST.$$$"); <BR>
      <P>&nbsp;&nbsp; /* change the time and date stamp*/ <BR>&nbsp;&nbsp; 
      setftime(fileno(fp), &amp;filet); <BR>
      <P>&nbsp;&nbsp; /* close and remove the temporary file */ <BR>&nbsp;&nbsp; 
      fclose(fp); <BR>
      <P>&nbsp;&nbsp; system("dir TEST.$$$"); <BR>
      <P>&nbsp;&nbsp; unlink("TEST.$$$"); <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setgraphbufsize <BR>功&nbsp; 能: 改变内部图形缓冲区的大小 <BR>用&nbsp; 法: 
      unsigned far setgraphbufsize(unsigned bufsize); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>#define BUFSIZE 1000 /* internal graphics buffer size */ <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int x, y, oldsize; <BR>&nbsp;&nbsp; char msg[80]; <BR>
      <P>&nbsp;&nbsp; /* set the size of the internal graphics buffer */ 
      <BR>&nbsp;&nbsp; /* before making a call to 
      initgraph.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ 
      <BR>&nbsp;&nbsp; oldsize = setgraphbufsize(BUFSIZE); <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; 
      /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      grapherrormsg(errorcode)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Press any key to halt:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      getch(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an 
      error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; x = getmaxx() / 2; <BR>&nbsp;&nbsp; y = getmaxy() / 2; 
<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -