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

📄 fg.htm

📁 c语言基本的应用便于初学者学习使用 简单易懂
💻 HTM
📖 第 1 页 / 共 5 页
字号:

<p>&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getche <br>
功&nbsp; 能: 从控制台取字符(带回显) <br>
用&nbsp; 法: int getche(void); <br>
程序例: </p>

<p>#include &lt;stdio.h&gt; <br>
#include &lt;conio.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; char ch; </p>

<p>&nbsp;&nbsp; printf(&quot;Input a character:&quot;); <br>
&nbsp;&nbsp; ch = getche(); <br>
&nbsp;&nbsp; printf(&quot;\nYou input a '%c'\n&quot;, ch); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getcolor <br>
功&nbsp; 能: 返回当前画线颜色 <br>
用&nbsp; 法: int far getcolor(void); <br>
程序例: </p>

<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; </p>

<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <br>
&nbsp;&nbsp; int color, midx, midy; <br>
&nbsp;&nbsp; char colname[35]; </p>

<p>/* initialize graphics and local variables */ <br>
&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </p>

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

<p>&nbsp;&nbsp; midx = getmaxx() / 2; <br>
&nbsp;&nbsp; midy = getmaxy() / 2; <br>
&nbsp;&nbsp; setcolor(getmaxcolor()); </p>

<p>/* for centering text on the display */ <br>
&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT); </p>

<p>/* get the current drawing color */ <br>
&nbsp;&nbsp; color = getcolor(); </p>

<p>/* convert color value into a string */ <br>
&nbsp;&nbsp; itoa(color, colname, 10); <br>
&nbsp;&nbsp; strcat(colname, <br>
&nbsp;&nbsp; &quot; is the current drawing color.&quot;); </p>

<p>/* display a message */ <br>
&nbsp;&nbsp; outtextxy(midx, midy, colname); </p>

<p>/* clean up */ <br>
&nbsp;&nbsp; getch(); <br>
&nbsp;&nbsp; closegraph(); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getcurdir <br>
功&nbsp; 能: 取指定驱动器的当前目录 <br>
用&nbsp; 法: int getcurdir(int drive, char *direc); <br>
程序例: </p>

<p>#include &lt;dir.h&gt; <br>
#include &lt;stdio.h&gt; <br>
#include &lt;string.h&gt; </p>

<p>char *current_directory(char *path) <br>
{ <br>
&nbsp;&nbsp; strcpy(path, &quot;X:\\&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* fill string with form of response: X:\ */ <br>
&nbsp;&nbsp; path[0] = 'A' + getdisk();&nbsp;&nbsp;&nbsp; /*
replace X with current drive letter */ <br>
&nbsp;&nbsp; getcurdir(0, path+3);&nbsp; /* fill rest of string
with current directory */ <br>
&nbsp;&nbsp; return(path); <br>
} </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; char curdir[MAXPATH]; </p>

<p>&nbsp;&nbsp; current_directory(curdir); <br>
&nbsp;&nbsp; printf(&quot;The current directory is %s\n&quot;,
curdir); </p>

<p>&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getcwd <br>
功&nbsp; 能: 取当前工作目录 <br>
用&nbsp; 法: char *getcwd(char *buf, int n); <br>
程序例: </p>

<p>#include &lt;stdio.h&gt; <br>
#include &lt;dir.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; char buffer[MAXPATH]; </p>

<p>&nbsp;&nbsp; getcwd(buffer, MAXPATH); <br>
&nbsp;&nbsp; printf(&quot;The current directory is: %s\n&quot;,
buffer); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getdate <br>
功&nbsp; 能: 取DOS日期 <br>
用&nbsp; 法: void getdate(struct *dateblk); <br>
程序例: </p>

<p>#include &lt;dos.h&gt; <br>
#include &lt;stdio.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; struct date d; </p>

<p>&nbsp;&nbsp; getdate(&amp;d); <br>
&nbsp;&nbsp; printf(&quot;The current year is: %d\n&quot;, <br>
&nbsp;&nbsp; d.da_year); <br>
&nbsp;&nbsp; printf(&quot;The current day is: %d\n&quot;, <br>
&nbsp;&nbsp; d.da_day); <br>
&nbsp;&nbsp; printf(&quot;The current month is: %d\n&quot;, <br>
&nbsp;&nbsp; d.da_mon); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getdefaultpalette <br>
功&nbsp; 能: 返回调色板定义结构 <br>
用&nbsp; 法: struct palettetype *far getdefaultpalette(void); <br>
程序例: </p>

<p>#include &lt;graphics.h&gt; <br>
#include &lt;stdlib.h&gt; <br>
#include &lt;stdio.h&gt; <br>
#include &lt;conio.h&gt; </p>

<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <br>
&nbsp;&nbsp; int i; </p>

<p>/* structure for returning palette copy */ <br>
&nbsp;&nbsp; struct palettetype far *pal=(void *) 0; </p>

<p>/* initialize graphics and local variables */ <br>
&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </p>

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

<p>&nbsp;&nbsp; setcolor(getmaxcolor()); </p>

<p>/* return a pointer to the default palette */ <br>
&nbsp;&nbsp; pal = getdefaultpalette(); </p>

<p>&nbsp;&nbsp; for (i=0; i&lt;16; i++) <br>
&nbsp;&nbsp; { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;colors[%d] =
%d\n&quot;, i, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pal-&gt;colors[i]); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <br>
&nbsp;&nbsp; } </p>

<p>/* clean up */ <br>
&nbsp;&nbsp; getch(); <br>
&nbsp;&nbsp; closegraph(); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getdisk <br>
功&nbsp; 能: 取当前磁盘驱动器号 <br>
用&nbsp; 法: int getdisk(void); <br>
程序例: </p>

<p>#include &lt;stdio.h&gt; <br>
#include &lt;dir.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; int disk; </p>

<p>&nbsp;&nbsp; disk = getdisk() + 'A'; <br>
&nbsp;&nbsp; printf(&quot;The current drive is: %c\n&quot;, <br>
&nbsp;&nbsp;&nbsp; disk); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getdrivername <br>
功&nbsp; 能:
返回指向包含当前图形驱动程序名字的字符串指针
<br>
用&nbsp; 法: char *getdrivename(void); <br>
程序例: </p>

<p>#include &lt;graphics.h&gt; <br>
#include &lt;stdlib.h&gt; <br>
#include &lt;stdio.h&gt; <br>
#include &lt;conio.h&gt; </p>

<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; </p>

<p>/* stores the device driver name */ <br>
&nbsp;&nbsp; char *drivername; </p>

<p>/* initialize graphics and local variables */ <br>
&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </p>

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

<p>&nbsp;&nbsp; setcolor(getmaxcolor()); </p>

<p>/* get name of the device driver in use */ <br>
&nbsp;&nbsp; drivername = getdrivername(); </p>

<p>/* for centering text on the screen */ <br>
&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT); </p>

<p>/* output the name of the driver */ <br>
&nbsp;&nbsp; outtextxy(getmaxx() / 2, getmaxy() / 2, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drivername); </p>

<p>/* clean up */ <br>
&nbsp;&nbsp; getch(); <br>
&nbsp;&nbsp; closegraph(); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getdta <br>
功&nbsp; 能: 取磁盘传输地址 <br>
用&nbsp; 法: char far *getdta(void); <br>
程序例: </p>

<p>#include &lt;dos.h&gt; <br>
#include &lt;stdio.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; char far *dta; </p>

<p>&nbsp;&nbsp; dta = getdta(); <br>
&nbsp;&nbsp; printf(&quot;The current disk transfer \ <br>
&nbsp;&nbsp; address is: %Fp\n&quot;, dta); <br>
&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getenv <br>
功&nbsp; 能: 从环境中取字符串 <br>
用&nbsp; 法: char *getenv(char *envvar); <br>
程序例: </p>

<p>#include &lt;stdlib.h&gt; <br>
#include &lt;stdio.h&gt; <br>
&nbsp; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp;&nbsp; char *s; </p>

<p>&nbsp;&nbsp;&nbsp; s=getenv(&quot;COMSPEC&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* get the comspec environment parameter */ <br>
&nbsp;&nbsp;&nbsp; printf(&quot;Command processor: %s\n&quot;,s);&nbsp;&nbsp;
/* display comspec parameter */ </p>

<p>&nbsp;&nbsp;&nbsp; return 0; <br>
} <br>
&nbsp; <br>
&nbsp; <br>
&nbsp; </p>

<p>函数名: getfat, getfatd <br>
功&nbsp; 能: 取文件分配表信息 <br>
用&nbsp; 法: void getfat(int drive, struct fatinfo *fatblkp); <br>
程序例: </p>

<p>#include &lt;stdio.h&gt; <br>
#include &lt;dos.h&gt; </p>

<p>int main(void) <br>
{ <br>
&nbsp;&nbsp; struct fatinfo diskinfo; <br>
&nbsp;&nbsp; int flag = 0; </p>

<p>&nbsp;&nbsp; printf(&quot;Please insert disk in drive
A\n&quot;); <br>
&nbsp;&nbsp; getchar(); </p>

<p>&nbsp;&nbsp; getfat(1, &amp;diskinfo); <br>
/* get drive information */ </p>

<p>&nbsp;&nbsp; printf(&quot;\nDrive A: is &quot;); <br>
&nbsp;&nbsp; switch((unsigned char) diskinfo.fi_fatid) <br>
&nbsp;&nbsp; { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0xFD: <br>
&nbsp;printf(&quot;360K low density\n&quot;); <br>
&nbsp;break; </p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0xF9: <br>
&nbsp;printf(&quot;1.2 Meg high density\n&quot;); <br>
&nbsp;break; </p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: <br>
&nbsp;printf(&quot;unformatted\n&quot;); <br>
&nbsp;flag = 1; <br>
&nbsp;&nbsp; } </p>

<p>&nbsp;&nbsp; if (!flag) <br>
&nbsp;&nbsp; { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&nbsp; sectors per
cluster %5d\n&quot;, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diskinfo.fi_sclus); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&nbsp;&nbsp; number
of clusters %5d\n&quot;, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diskinfo.fi_nclus); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&nbsp;&nbsp;&nbsp;&nbsp;

⌨️ 快捷键说明

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