[ ッ环UNIX::UNIXм砃戈腳畐 ]   GB | BIG5

 > 絪祘м砃 > C/C++ > タゅ
C粂ē畐ㄧ计(G摸ダ) - 1
セゅ:http://www.asfocus.com : (2001-07-28 07:05:00)
ㄧ计: gcvt
 : р疊翴计锣传Θ才﹃
ノ 猭: char *gcvt(double value, int ndigit, char *buf);
祘ㄒ:
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
char str[25];
double num;
int sig = 5; /* significant digits */

/* a regular number */
num = 9.876;
gcvt(num, sig, str);
printf("string = %s\n", str);

/* a negative number */
num = -123.4567;
gcvt(num, sig, str);
printf("string = %s\n", str);

/* scientific notation */
num = 0.678e5;
gcvt(num, sig, str);
printf("string = %s\n", str);

return(0);
}




ㄧ计: geninterrupt
 : 玻ネ硁い耞
ノ 猭: void geninterrupt(int intr_num);
祘ㄒ:

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

/* function prototype */
void writechar(char ch);

int main(void)
{
clrscr();
gotoxy(80,25);
writechar('*');
getch();
return 0;
}

/*
outputs a character at the current cursor
position using the video BIOS to avoid the
scrolling of the screen when writing to
location (80,25).
*/

void writechar(char ch)
{
struct text_info ti;
/* grab current text settings */
gettextinfo(&ti);
/* interrupt 0x10 sub-function 9 */
_AH = 9;
/* character to be output */
_AL = ch;
_BH = 0; /* video page */
_BL = ti.attribute; /* video attribute */
_CX = 1; /* repetition factor */
geninterrupt(0x10); /* output the char */
}



ㄧ计: getarccoords
 : 眔程Ω秸ノarcГ夹
ノ 猭: void far getarccoords(struct arccoordstype far *arccoords);
祘ㄒ:

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

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
struct arccoordstype arcinfo;
int midx, midy;
int stangle = 45, endangle = 270;
char sstr[80], estr[80];

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

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

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

/* draw arc and get coordinates */
setcolor(getmaxcolor());
arc(midx, midy, stangle, endangle, 100);
getarccoords(&arcinfo);

/* convert arc information into strings */
sprintf(sstr, "*- (%d, %d)",
arcinfo.xstart, arcinfo.ystart);
sprintf(estr, "*- (%d, %d)",
arcinfo.xend, arcinfo.yend);

/* output the arc information */
outtextxy(arcinfo.xstart,
arcinfo.ystart, sstr);
outtextxy(arcinfo.xend,
arcinfo.yend, estr);

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




ㄧ计: getaspectratio
 : 讽玡瓜家Α羇绢ゑ
ノ 猭: void far getaspectratio(int far *xasp, int far *yasp);
祘ㄒ:

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

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xasp, yasp, midx, midy;

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

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

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

/* get current aspect ratio settings */
getaspectratio(&xasp, &yasp);

/* draw normal circle */
circle(midx, midy, 100);
getch();

/* draw wide circle */
cleardevice();
setaspectratio(xasp/2, yasp);
circle(midx, midy, 100);
getch();

/* draw narrow circle */
cleardevice();
setaspectratio(xasp, yasp/2);
circle(midx, midy, 100);

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




ㄧ计: getbkcolor
 : 讽玡璉春肅︹
ノ 猭: int far getbkcolor(void);
祘ㄒ:

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

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int bkcolor, midx, midy;
char bkname[35];

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

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

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

/* for centering text on the display */
settextjustify(CENTER_TEXT, CENTER_TEXT);

/* get the current background color */
bkcolor = getbkcolor();

/* convert color value into a string */
itoa(bkcolor, bkname, 10);
strcat(bkname,
" is the current background color.");

/* display a message */
outtextxy(midx, midy, bkname);

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




ㄧ计: getc
 : 眖瑈い才
ノ 猭: int getc(FILE *stream);
祘ㄒ:

#include <stdio.h>

int main(void)
{
char ch;

printf("Input a character:");
/* read a character from the
standard input stream */
ch = getc(stdin);
printf("The character input was: '%c'\n",
ch);
return 0;
}




ㄧ计: getcbrk
 : 莉Control_break砞竚
ノ 猭: int getcbrk(void);
祘ㄒ:

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

int main(void)
{
if (getcbrk())
printf("Cntrl-brk flag is on\n");
else
printf("Cntrl-brk flag is off\n");

return 0;
}



ㄧ计: getch
 : 眖北礚陪才
ノ 猭: int getch(void);
祘ㄒ:

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

int main(void)
{
char ch;

printf("Input a character:");
ch = getche();
printf("\nYou input a '%c'\n", ch);
return 0;
}



ㄧ计: getchar
 : 眖stdin瑈い弄才
ノ 猭: int getchar(void);
祘ㄒ:

#include <stdio.h>

int main(void)
{
int c;

/* Note that getchar reads from stdin and
is line buffered; this means it will
not return until you press ENTER. */

while ((c = getchar()) != '\n')
printf("%c", c);

return 0;
}



ㄧ计: getche
 : 眖北才(盿陪)
ノ 猭: int getche(void);
祘ㄒ:

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

int main(void)
{
char ch;

printf("Input a character:");
ch = getche();
printf("\nYou input a '%c'\n", ch);
return 0;
}



ㄧ计: getcolor
 : 讽玡礶絬肅︹
ノ 猭: int far getcolor(void);
祘ㄒ:

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

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

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

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

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

/* for centering text on the display */
settextjustify(CENTER_TEXT, CENTER_TEXT);

/* get the current drawing color */
color = getcolor();

/* convert color value into a string */
itoa(color, colname, 10);
strcat(colname,
" is the current drawing color.");

/* display a message */
outtextxy(midx, midy, colname);

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



ㄧ计: getcurdir
 : ﹚臱笆竟讽玡ヘ魁
ノ 猭: int getcurdir(int drive, char *direc);
祘ㄒ:

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

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

int main(void)
{
char curdir[MAXPATH];

current_directory(curdir);
printf("The current directory is %s\n", curdir);

return 0;
}



ㄧ计: getcwd
 : 讽玡ヘ魁
ノ 猭: char *getcwd(char *buf, int n);
祘ㄒ:

#include <stdio.h>
#include <dir.h>

int main(void)
{
char buffer[MAXPATH];

getcwd(buffer, MAXPATH);
printf("The current directory is: %s\n", buffer);
return 0;
}
(http://www.fanqiang.com)
    秈UNIX阶韭

闽ゅ彻
C粂ē畐ㄧ计(W摸ダ) (2001-10-27 13:05:00)
C粂ē畐ㄧ计(V摸ダ) (2001-10-27 09:05:00)
C粂ē畐ㄧ计(U摸ダ) (2001-10-27 08:05:01)
C粂ē畐ㄧ计(T摸ダ) (2001-10-27 07:05:00)
C粂ē畐ㄧ计(S摸ダ) - 3 (2001-10-26 09:00:00)
C粂ē畐ㄧ计(S摸ダ) - 2 (2001-10-26 08:00:01)
C粂ē畐ㄧ计(S摸ダ) - 1 (2001-10-26 07:00:00)
C粂ē畐ㄧ计(R摸ダ) (2001-10-25 09:00:01)
C粂ē畐ㄧ计(Q摸ダ) (2001-10-25 08:00:03)
C粂ē畐ㄧ计(P摸ダ) (2001-10-25 07:00:01)

===闽===
 

」  荚眏 舧だㄉ  」