- 浏览: 606943 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (365)
- Java 基础知识(笔试面试有用) (35)
- SQL 相关 (11)
- Oracle笔试 (1)
- Java 笔试面试 (11)
- LINUX (12)
- ExtJS (21)
- Javascript (17)
- WebGIS (2)
- 软件工程 (3)
- 数据库 (17)
- 项目管理 (63)
- 工作流 (2)
- 计算机网络 (3)
- ZigBee技术及应用 (24)
- 单片机(AVR Studio) (7)
- 项目人力资源管理 (3)
- 项目管理高级知识 (4)
- JAVA技术 (12)
- 项目管理中的概念 (3)
- SQL SERVER (1)
- C++ (1)
- C/C++编程经验 (12)
- C和C++面试笔试题 (12)
- 其他IT技术笔试面试 (6)
- 名企笔试面试集锦 (16)
- 非技术 (10)
- C#相关 (1)
- Matlab相关 (2)
- 计算机专业课相关 (2)
- Web Service (1)
- Excel 使用 (1)
- PhotoShop相关 (4)
- ASP 相关 (2)
- android (1)
- Java WEB 相关 (1)
- web 安全相关 (7)
- 网络安全 (1)
- IBatis (1)
- web 开发技巧 (2)
- css 相关 (1)
- Ruby相关 (2)
- 生活 (3)
- 操作系统安全相关 (6)
- 操作系统相关 (1)
- PHP相关 (3)
- 开发经验 (12)
- Redis (1)
最新评论
函数名: detectgraph
功 能: 通过检测硬件确定图形驱动程序和模式
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例:
#include ;
#include ;
#include ;
#include ;
/* names of the various cards supported */
char *dname[] = { "requests detection",
"a CGA",
"an MCGA",
"an EGA",
"a 64K EGA",
"a monochrome EGA",
"an IBM 8514",
"a Hercules monochrome",
"an AT&T 6300 PC",
"a VGA",
"an IBM 3270 PC"
};
int main(void)
{
/* returns detected hardware info. */
int gdriver, gmode, errorcode;
/* detect graphics hardware available */
detectgraph(&gdriver, &gmode);
/* read result of detectgraph call */
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 */
}
/* display the information detected */
clrscr();
printf("You have %s video display \
card.\n", dname[gdriver]);
printf("Press any key to halt:");
getch();
return 0;
}
函数名: difftime
功 能: 计算两个时刻之间的时间差
用 法: double difftime(time_t time2, time_t time1);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
time_t first, second;
clrscr();
first = time(NULL); /* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */
printf("The difference is: %f \
seconds\n",difftime(second,first));
getch();
return 0;
}
函数名: disable
功 能: 屏蔽中断
用 法: void disable(void);
程序例:
/***NOTE: This is an interrupt service
routine. You cannot compile this program
with Test Stack Overflow turned on and
get an executable file that operates
correctly. */
#include ;
#include ;
#include ;
#define INTR 0X1C /* The clock tick
interrupt */
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/* disable interrupts during the handling of
the interrupt */
disable();
/* increase the global counter */
count++;
/* reenable interrupts at the end of the
handler */
enable();
/* call the old routine */
oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR, handler);
/* loop until the counter exceeds 20 */
while (count 函数名: div
功 能: 将两个整数相除, 返回商和余数
用 法: div_t (int number, int denom);
程序例:
#include ;
#include ;
div_t x;
int main(void)
{
x = div(10,3);
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);
return 0;
}
函数名: dosexterr
功 能: 获取扩展DOS错误信息
用 法: int dosexterr(struct DOSERR *dblkp);
程序例:
#include ;
#include ;
int main(void)
{
FILE *fp;
struct DOSERROR info;
fp = fopen("perror.dat","r");
if (!fp) perror("Unable to open file for
reading");
dosexterr(&info);
printf("Extended DOS error \
information:\n");
printf(" Extended error: \
%d\n",info.exterror);
printf(" Class: \
%x\n",info.class);
printf(" Action: \
%x\n",info.action);
printf(" Error Locus: \
%x\n",info.locus);
return 0;
}
函数名: dostounix
功 能: 转换日期和时间为UNIX时间格式
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
time_t t;
struct time d_time;
struct date d_date;
struct tm *local;
getdate(&d_date);
gettime(&d_time);
t = dostounix(&d_date, &d_time);
local = localtime(&t);
printf("Time and Date: %s\n", \
asctime(local));
return 0;
}
函数名: drawpoly
功 能: 画多边形
用 法: void far drawpoly(int numpoints, int far *polypoints);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* our polygon array */
int poly[10];
/* 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();
/* terminate with an error code */
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
poly[0] = 20; /* 1st vertext */
poly[1] = maxy / 2;
poly[2] = maxx - 20; /* 2nd */
poly[3] = 20;
poly[4] = maxx - 50; /* 3rd */
poly[5] = maxy - 20;
poly[6] = maxx / 2; /* 4th */
poly[7] = maxy / 2;
/*
drawpoly doesn't automatically close
the polygon, so we close it.
*/
poly[8] = poly[0];
poly[9] = poly[1];
/* draw the polygon */
drawpoly(5, poly);
/* clean up */
getch();
closegraph();
return 0;
}
函数名: dup
功 能: 复制一个文件句柄
用 法: int dup(int handle);
程序例:
#include ;
#include ;
#include ;
#include ;
void flush(FILE *stream);
int main(void)
{
FILE *fp;
char msg[] = "This is a test";
/* create a file */
fp = fopen("DUMMY.FIL", "w");
/* write some data to the file */
fwrite(msg, strlen(msg), 1, fp);
clrscr();
printf("Press any key to flush \
DUMMY.FIL:");
getch();
/* flush the data to DUMMY.FIL without
closing it */
flush(fp);
printf("\nFile was flushed, Press any \
key to quit:");
getch();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
/* flush TC's internal buffer */
fflush(stream);
/* make a duplicate file handle */
duphandle = dup(fileno(stream));
/* close the duplicate handle to flush the
DOS buffer */
close(duphandle);
}
函数名: dup2
功 能: 复制文件句柄
用 法: int dup2(int oldhandle, int newhandle);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
#define STDOUT 1
int nul, oldstdout;
char msg[] = "This is a test";
/* create a file */
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
/* create a duplicate handle for standard
output */
oldstdout = dup(STDOUT);
/*
redirect standard output to DUMMY.FIL
by duplicating the file handle onto the
file handle for standard output.
*/
dup2(nul, STDOUT);
/* close the handle for DUMMY.FIL */
close(nul);
/* will be redirected into DUMMY.FIL */
write(STDOUT, msg, strlen(msg));
/* restore original standard output
handle */
dup2(oldstdout, STDOUT);
/* close duplicate handle for STDOUT */
close(oldstdout);
return 0;
}
函数名: ecvt
功 能: 把一个浮点数转换为字符串
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10;
clrscr();
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/9.876;
string = ecvt(value, ndig, &dec, &sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign);
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/-123.45;
ndig= 15;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign);
return 0;
}
函数名: ellipse
功 能: 画一椭圆
用 法: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 0, endangle = 360;
int xradius = 100, yradius = 50;
/* initialize graphics, 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;
setcolor(getmaxcolor());
/* draw ellipse */
ellipse(midx, midy, stangle, endangle,
xradius, yradius);
/* clean up */
getch();
closegraph();
return 0;
}
函数名: enable
功 能: 开放硬件中断
用 法: void enable(void);
程序例:
/* ** NOTE:
This is an interrupt service routine. You can NOT compile this program
with Test Stack Overflow turned on and get an executable file which will
operate correctly.
*/
#include ;
#include ;
#include ;
/* The clock tick interrupt */
#define INTR 0X1C
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/*
disable interrupts during the handling of the interrupt
*/
disable();
/* increase the global counter */
count++;
/*
re enable interrupts at the end of the handler
*/
enable();
/* call the old routine */
oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR, handler);
/* loop until the counter exceeds 20 */
while (count 函数名: eof
功 能: 检测文件结束
用 法: int eof(int *handle);
程序例:
#include ;
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char msg[] = "This is a test";
char ch;
/* create a file */
handle = open("DUMMY.FIL",
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
/* write some data to the file */
write(handle, msg, strlen(msg));
/* seek to the beginning of the file */
lseek(handle, 0L, SEEK_SET);
/*
reads chars from the file until hit EOF
*/
do
{
read(handle, &ch, 1);
printf("%c", ch);
} while (!eof(handle));
close(handle);
return 0;
}
函数名: exec...
功 能: 装入并运行其它程序的函数
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
char *envp[]);
int execlp(char *pathname, char *arg0, arg1, .., NULL);
int execple(char *pathname, char *arg0, arg1, ..., NULL,
char *envp[]);
int execv(char *pathname, char *argv[]);
int execve(char *pathname, char *argv[], char *envp[]);
int execvp(char *pathname, char *argv[]);
int execvpe(char *pathname, char *argv[], char *envp[]);
程序例:
/* execv example */
#include ;
#include ;
#include ;
void main(int argc, char *argv[])
{
int i;
printf("Command line arguments:\n");
for (i=0; i函数名: exit
功 能: 终止程序
用 法: void exit(int status);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
int status;
printf("Enter either 1 or 2\n");
status = getch();
/* Sets DOS errorlevel */
exit(status - '0');
/* Note: this line is never reached */
return 0;
}
函数名: exp
功 能: 指数函数
用 法: double exp(double x);
程序例:
#include ;
#include ;
int main(void)
{
double result;
double x = 4.0;
result = exp(x);
printf("'e' raised to the power \
of %lf (e ^ %lf) = %lf\n",
x, x, result);
return 0;
}
CODE:
[Copy to clipboard]
函数名: exp
功 能: 指数函数
用 法: double exp(double x);
程序例:
#include ;
#include ;
int main(void)
{
double result;
double x = 4.0;
result = exp(x);
printf("'e' raised to the power \
of %lf (e ^ %lf) = %lf\n",
x, x, result);
return 0;
}
函数名: fabs
功 能: 返回浮点数的绝对值
用 法: double fabs(double x);
程序例:
#include ;
#include ;
int main(void)
{
float number = -1234.0;
printf("number: %f absolute value: %f\n",
number, fabs(number));
return 0;
}
函数名: farcalloc
功 能: 从远堆栈中申请空间
用 法: void far *farcalloc(unsigned long units, unsigned ling unitsz);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
char far *fptr;
char *str = "Hello";
/* allocate memory for the far pointer */
fptr = farcalloc(10, sizeof(char));
/* copy "Hello" into allocated memory */
/*
Note: movedata is used because you
might be in a small data model, in
which case a normal string copy routine
can not be used since it assumes the
pointer size is near.
*/
movedata(FP_SEG(str), FP_OFF(str),
FP_SEG(fptr), FP_OFF(fptr),
strlen(str));
/* display string (note the F modifier) */
printf("Far string is: %Fs\n", fptr);
/* free the memory */
farfree(fptr);
return 0;
}
函数名: farcoreleft
功 能: 返回远堆中未作用存储区大小
用 法: long farcoreleft(void);
程序例:
#include ;
#include ;
int main(void)
{
printf("The difference between the\
highest allocated block in the\
far\n");
printf("heap and the top of the far heap\
is: %lu bytes\n", farcoreleft());
return 0;
}
函数名: farfree
功 能: 从远堆中释放一块
用 法: void farfree(void);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
char far *fptr;
char *str = "Hello";
/* allocate memory for the far pointer */
fptr = farcalloc(10, sizeof(char));
/* copy "Hello" into allocated memory */
/*
Note: movedata is used because you might be in a small data model,
in which case a normal string copy routine can't be used since it
assumes the pointer size is near.
*/
movedata(FP_SEG(str), FP_OFF(str),
FP_SEG(fptr), FP_OFF(fptr),
strlen(str));
/* display string (note the F modifier) */
printf("Far string is: %Fs\n", fptr);
/* free the memory */
farfree(fptr);
return 0;
}
函数名: farmalloc
功 能: 从远堆中分配存储块
用 法: void far *farmalloc(unsigned long size);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
char far *fptr;
char *str = "Hello";
/* allocate memory for the far pointer */
fptr = farmalloc(10);
/* copy "Hello" into allocated memory */
/*
Note: movedata is used because we might
be in a small data model, in which case
a normal string copy routine can not be
used since it assumes the pointer size
is near.
*/
movedata(FP_SEG(str), FP_OFF(str),
FP_SEG(fptr), FP_OFF(fptr),
strlen(str));
/* display string (note the F modifier) */
printf("Far string is: %Fs\n", fptr);
/* free the memory */
farfree(fptr);
return 0;
}
函数名: farrealloc
功 能: 调整远堆中的分配块
用 法: void far *farrealloc(void far *block, unsigned long newsize);
程序例:
#include ;
#include ;
int main(void)
{
char far *fptr;
fptr = farmalloc(10);
printf("First address: %Fp\n", fptr);
fptr = farrealloc(fptr,20);
printf("New address : %Fp\n", fptr);
farfree(fptr);
return 0;
}
函数名: fclose
功 能: 关闭一个流
用 法: int fclose(FILE *stream);
程序例:
#include ;
#include ;
int main(void)
{
FILE *fp;
char buf[11] = "0123456789";
/* create a file containing 10 bytes */
fp = fopen("DUMMY.FIL", "w");
fwrite(&buf, strlen(buf), 1, fp);
/* close the file */
fclose(fp);
return 0;
}
函数名: fcloseall
功 能: 关闭打开流
用 法: int fcloseall(void);
程序例:
#include ;
int main(void)
{
int streams_closed;
/* open two streams */
fopen("DUMMY.ONE", "w");
fopen("DUMMY.TWO", "w");
/* close the open streams */
streams_closed = fcloseall();
if (streams_closed == EOF)
/* issue an error message */
perror("Error");
else
/* print result of fcloseall() function */
printf("%d streams were closed.\n", streams_closed);
return 0;
}
函数名: fcvt
功 能: 把一个浮点数转换为字符串
用 法: char *fcvt(double value, int ndigit, int *decpt, int *sign);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10;
clrscr();
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/9.876;
string = ecvt(value, ndig, &dec, &sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign);
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/-123.45;
ndig= 15;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
value = http://linux.chinaunix.net/techdoc/develop/2006/07/30/0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign);
return 0;
}
函数名: fdopen
功 能: 把流与一个文件句柄相接
用 法: FILE *fdopen(int handle, char *type);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
FILE *stream;
/* open a file */
handle = open("DUMMY.FIL", O_CREAT,
S_IREAD | S_IWRITE);
/* now turn the handle into a stream */
stream = fdopen(handle, "w");
if (stream == NULL)
printf("fdopen failed\n");
else
{
fprintf(stream, "Hello world\n");
fclose(stream);
}
return 0;
}
函数名: feof
功 能: 检测流上的文件结束符
用 法: int feof(FILE *stream);
程序例:
#include ;
int main(void)
{
FILE *stream;
/* open a file for reading */
stream = fopen("DUMMY.FIL", "r");
/* read a character from the file */
fgetc(stream);
/* check for EOF */
if (feof(stream))
printf("We have reached end-of-file\n");
/* close the file */
fclose(stream);
return 0;
}
函数名: ferror
功 能: 检测流上的错误
用 法: int ferror(FILE *stream);
程序例:
#include ;
int main(void)
{
FILE *stream;
/* open a file for writing */
stream = fopen("DUMMY.FIL", "w");
/* force an error condition by attempting to read */
(void) getc(stream);
if (ferror(stream)) /* test for an error on the stream */
{
/* display an error message */
printf("Error reading from DUMMY.FIL\n");
/* reset the error and EOF indicators */
clearerr(stream);
}
fclose(stream);
return 0;
}
函数名: fflush
功 能: 清除一个流
用 法: int fflush(FILE *stream);
程序例:
#include ;
#include ;
#include ;
#include ;
void flush(FILE *stream);
int main(void)
{
FILE *stream;
char msg[] = "This is a test";
/* create a file */
stream = fopen("DUMMY.FIL", "w");
/* write some data to the file */
fwrite(msg, strlen(msg), 1, stream);
clrscr();
printf("Press any key to flush\
DUMMY.FIL:");
getch();
/* flush the data to DUMMY.FIL without\
closing it */
flush(stream);
printf("\nFile was flushed, Press any key\
to quit:");
getch();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
/* flush the stream's internal buffer */
fflush(stream);
/* make a duplicate file handle */
duphandle = dup(fileno(stream));
/* close the duplicate handle to flush\
the DOS buffer */
close(duphandle);
}
函数名: fgetc
功 能: 从流中读取字符
用 法: int fgetc(FILE *stream);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
FILE *stream;
char string[] = "This is a test";
char ch;
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the beginning of the file */
fseek(stream, 0, SEEK_SET);
do
{
/* read a char from the file */
ch = fgetc(stream);
/* display the character */
putch(ch);
} while (ch != EOF);
fclose(stream);
return 0;
}
函数名: fgetchar
功 能: 从流中读取字符
用 法: int fgetchar(void);
程序例:
#include ;
int main(void)
{
char ch;
/* prompt the user for input */
printf("Enter a character followed by \
;: ");
/* read the character from stdin */
ch = fgetchar();
/* display what was read */
printf("The character read is: '%c'\n",
ch);
return 0;
}
函数名: fgetpos
功 能: 取得当前文件的句柄
用 法: int fgetpos(FILE *stream);
程序例:
#include ;
#include ;
int main(void)
{
FILE *stream;
char string[] = "This is a test";
fpos_t filepos;
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* report the file pointer position */
fgetpos(stream, &filepos);
printf("The file pointer is at byte\
%ld\n", filepos);
fclose(stream);
return 0;
}
函数名: fgets
功 能: 从流中读取一字符串
用 法: char *fgets(char *string, int n, FILE *stream);
程序例:
#include ;
#include ;
int main(void)
{
FILE *stream;
char string[] = "This is a test";
char msg[20];
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(string)+1, stream);
/* display the string */
printf("%s", msg);
fclose(stream);
return 0;
}
函数名: filelength
功 能: 取文件长度字节数
用 法: long filelength(int handle);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* create a file containing 10 bytes */
handle = open("DUMMY.FIL", O_CREAT);
write(handle, buf, strlen(buf));
/* display the size of the file */
printf("file length in bytes: %ld\n",
filelength(handle));
/* close the file */
close(handle);
return 0;
}
函数名: fillellipse
功 能: 画出并填充一椭圆
用 法: void far fillellipse(int x, int y, int xradius, int yradius);
程序例:
#include ;
#include ;
int main(void)
{
int gdriver = DETECT, gmode;
int xcenter, ycenter, i;
initgraph(&gdriver,&gmode,"");
xcenter = getmaxx() / 2;
ycenter = getmaxy() / 2;
for (i=0; i函数名: fillpoly
功 能: 画并填充一个多边形
用 法: void far fillpoly(int numpoints, int far *polypoints);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int i, maxx, maxy;
/* our polygon array */
int poly[8];
/* initialize graphics, 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();
maxy = getmaxy();
poly[0] = 20; /* 1st vertext */
poly[1] = maxy / 2;
poly[2] = maxx - 20; /* 2nd */
poly[3] = 20;
poly[4] = maxx - 50; /* 3rd */
poly[5] = maxy - 20;
/*
4th vertex. fillpoly automatically
closes the polygon.
*/
poly[6] = maxx / 2;
poly[7] = maxy / 2;
/* loop through the fill patterns */
for (i=EMPTY_FILL; i函数名: findfirst, findnext
功 能: 搜索磁盘目录; 取得下一个匹配的findfirst模式的文件
用 法: int findfirst(char *pathname, struct ffblk *ffblk, int attrib);
int findnext(struct ffblk *ffblk);
程序例:
/* findnext example */
#include ;
#include ;
int main(void)
{
struct ffblk ffblk;
int done;
printf("Directory listing of *.*\n");
done = findfirst("*.*",&ffblk,0);
while (!done)
{
printf(" %s\n", ffblk.ff_name);
done = findnext(&ffblk);
}
return 0;
}
函数名: floodfill
功 能: 填充一个有界区域
用 法: void far floodfill(int x, int y, int border);
程序例:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* initialize graphics, 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();
maxy = getmaxy();
/* select drawing color */
setcolor(getmaxcolor());
/* select fill color */
setfillstyle(SOLID_FILL, getmaxcolor());
/* draw a border around the screen */
rectangle(0, 0, maxx, maxy);
/* draw some circles */
circle(maxx / 3, maxy /2, 50);
circle(maxx / 2, 20, 100);
circle(maxx-20, maxy-50, 75);
circle(20, maxy-20, 25);
/* wait for a key */
getch();
/* fill in bounded region */
floodfill(2, 2, getmaxcolor());
/* clean up */
getch();
closegraph();
return 0;
}
函数名: floor
功 能: 向下舍入
用 法: double floor(double x);
程序例:
#include ;
#include ;
int main(void)
{
double number = 123.54;
double down, up;
down = floor(number);
up = ceil(number);
printf("original number %10.2lf\n",
number);
printf("number rounded down %10.2lf\n",
down);
printf("number rounded up %10.2lf\n",
up);
return 0;
}
函数名: flushall
功 能: 清除所有缓冲区
用 法: int flushall(void);
程序例:
#include ;
int main(void)
{
FILE *stream;
/* create a file */
stream = fopen("DUMMY.FIL", "w");
/* flush all open streams */
printf("%d streams were flushed.\n",
flushall());
/* close the file */
fclose(stream);
return 0;
}
函数名: fmod
功 能: 计算x对y的模, 即x/y的余数
用 法: double fmod(double x, double y);
程序例:
#include ;
#include ;
int main(void)
{
double x = 5.0, y = 2.0;
double result;
result = fmod(x,y);
printf("The remainder of (%lf / %lf) is \
%lf\n", x, y, result);
return 0;
}
函数名: fnmerge
功 能: 建立新文件名
用 法: void fnerge(char *path, char *drive, char *dir);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
char s[MAXPATH];
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];
getcwd(s,MAXPATH); /* get the current working directory */
strcat(s,"\\"); /* append on a trailing \ character */
fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */
strcpy(file,"DATA");
strcpy(ext,".TXT");
fnmerge(s,drive,dir,file,ext); /* merge everything into one string */
puts(s); /* display resulting string */
return 0;
}
函数名: fopen
功 能: 打开一个流
用 法: FILE *fopen(char *filename, char *type);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
char *s;
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];
int flags;
s=getenv("COMSPEC"); /* get the comspec environment parameter */
flags=fnsplit(s,drive,dir,file,ext);
printf("Command processor info:\n");
if(flags & DRIVE)
printf("\tdrive: %s\n",drive);
if(flags & DIRECTORY)
printf("\tdirectory: %s\n",dir);
if(flags & FILENAME)
printf("\tfile: %s\n",file);
if(flags & EXTENSION)
printf("\textension: %s\n",ext);
return 0;
}
函数名: fprintf
功 能: 传送格式化输出到一个流中
用 法: int fprintf(FILE *stream, char *format[, argument,...]);
程序例:
/* Program to create backup of the
AUTOEXEC.BAT file */
#include ;
int main(void)
{
FILE *in, *out;
if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
== NULL)
{
fprintf(stderr, "Cannot open input \
file.\n");
return 1;
}
if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
== NULL)
{
fprintf(stderr, "Cannot open output \
file.\n");
return 1;
}
while (!feof(in))
fputc(fgetc(in), out);
fclose(in);
fclose(out);
return 0;
}
函数名: FP_OFF
功 能: 获取远地址偏移量
用 法: unsigned FP_OFF(void far *farptr);
程序例:
/* FP_OFF */
#include ;
#include ;
int main(void)
{
char *str = "fpoff.c";
printf("The offset of this file in memory\
is: %Fp\n", FP_OFF(str));
return 0;
}
函数名: FP_SEG
功 能: 获取远地址段值
用 法: unsigned FP_SEG(void far *farptr);
程序例:
/* FP_SEG */
#include ;
#include ;
int main(void)
{
char *filename = "fpseg.c";
printf("The offset of this file in memory\
is: %Fp\n", FP_SEG(filename));
return(0);
}
函数名: fputc
功 能: 送一个字符到一个流中
用 法: int fputc(int ch, FILE *stream);
程序例:
#include ;
int main(void)
{
char msg[] = "Hello world";
int i = 0;
while (msg)
{
fputc(msg, stdout);
i++;
}
return 0;
}
函数名: fputchar
功 能: 送一个字符到标准输出流(stdout)中
用 法: int fputchar(char ch);
程序例:
#include ;
int main(void)
{
char msg[] = "This is a test";
int i = 0;
while (msg)
{
fputchar(msg);
i++;
}
return 0;
}
函数名: fputs
功 能: 送一个字符到一个流中
用 法: int fputs(char *string, FILE *stream);
程序例:
#include ;
int main(void)
{
/* write a string to standard output */
fputs("Hello world\n", stdout);
return 0;
}
函数名: fread
功 能: 从一个流中读数据
用 法: int fread(void *ptr, int size, int nitems, FILE *stream);
程序例:
#include ;
#include ;
int main(void)
{
FILE *stream;
char msg[] = "this is a test";
char buf[20];
if ((stream = fopen("DUMMY.FIL", "w+"))
== NULL)
{
fprintf(stderr,
"Cannot open output file.\n");
return 1;
}
/* write some data to the file */
fwrite(msg, strlen(msg)+1, 1, stream);
/* seek to the beginning of the file */
fseek(stream, SEEK_SET, 0);
/* read the data and display it */
fread(buf, strlen(msg)+1, 1, stream);
printf("%s\n", buf);
fclose(stream);
return 0;
}
函数名: free
功 能: 释放已分配的块
用 法: void free(void *ptr);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
char *str;
/* allocate memory for string */
str = malloc(10);
/* copy "Hello" to string */
strcpy(str, "Hello");
/* display string */
printf("String is %s\n", str);
/* free memory */
free(str);
return 0;
}
函数名: freemem
功 能: 释放先前分配的DOS内存块
用 法: int freemem(unsigned seg);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
unsigned int size, segp;
int stat;
size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat 函数名: freopen
功 能: 替换一个流
用 法: FILE *freopen(char *filename, char *type, FILE *stream);
程序例:
#include ;
int main(void)
{
/* redirect standard output to a file */
if (freopen("OUTPUT.FIL", "w", stdout)
== NULL)
fprintf(stderr, "error redirecting\
stdout\n");
/* this output will go to a file */
printf("This will go into a file.");
/* close the standard output stream */
fclose(stdout);
return 0;
}
函数名: frexp
功 能: 把一个双精度数分解为尾数的指数
用 法: double frexp(double value, int *eptr);
程序例:
#include ;
#include ;
int main(void)
{
double mantissa, number;
int exponent;
number = 8.0;
mantissa = frexp(number, &exponent);
printf("The number %lf is ", number);
printf("%lf times two to the ", mantissa);
printf("power of %d\n", exponent);
return 0;
}
函数名: fscanf
功 能: 从一个流中执行格式化输入
用 法: int fscanf(FILE *stream, char *format[,argument...]);
程序例:
#include ;
#include ;
int main(void)
{
int i;
printf("Input an integer: ");
/* read an integer from the
standard input stream */
if (fscanf(stdin, "%d", &i))
printf("The integer read was: %i\n",
i);
else
{
fprintf(stderr, "Error reading an \
integer from stdin.\n");
exit(1);
}
return 0;
}
函数名: fseek
功 能: 重定位流上的文件指针
用 法: int fseek(FILE *stream, long offset, int fromwhere);
程序例:
#include ;
long filesize(FILE *stream);
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream));
fclose(stream);
return 0;
}
long filesize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
函数名: fsetpos
功 能: 定位流上的文件指针
用 法: int fsetpos(FILE *stream, const fpos_t *pos);
程序例:
#include ;
#include ;
void showpos(FILE *stream);
int main(void)
{
FILE *stream;
fpos_t filepos;
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* save the file pointer position */
fgetpos(stream, &filepos);
/* write some data to the file */
fprintf(stream, "This is a test");
/* show the current file position */
showpos(stream);
/* set a new file position, display it */
if (fsetpos(stream, &filepos) == 0)
showpos(stream);
else
{
fprintf(stderr, "Error setting file \
pointer.\n");
exit(1);
}
/* close the file */
fclose(stream);
return 0;
}
void showpos(FILE *stream)
{
fpos_t pos;
/* display the current file pointer
position of a stream */
fgetpos(stream, &pos);
printf("File position: %ld\n", pos);
}
函数名: fstat
功 能: 获取打开文件信息
用 法: int fstat(char *handle, struct stat *buff);
程序例:
#include ;
#include ;
#include ;
int main(void)
{
struct stat statbuf;
FILE *stream;
/* open a file for update */
if ((stream = fopen("DUMMY.FIL", "w+"))
== NULL)
{
fprintf(stderr, "Cannot open output \
file.\n");
return(1);
}
fprintf(stream, "This is a test");
fflush(stream);
/* get information about the file */
fstat(fileno(stream), &statbuf);
fclose(stream);
/* display the information returned */
if (statbuf.st_mode & S_IFCHR)
printf("Handle refers to a device.\n");
if (statbuf.st_mode & S_IFREG)
printf("Handle refers to an ordinary \
file.\n");
if (statbuf.st_mode & S_IREAD)
printf("User has read permission on \
file.\n");
if (statbuf.st_mode & S_IWRITE)
printf("User has write permission on \
file.\n");
printf("Drive letter of file: %c\n",
'A'+statbuf.st_dev);
printf("Size of file in bytes: %ld\n",
statbuf.st_size);
printf("Time file last opened: %s\n",
ctime(&statbuf.st_ctime));
return 0;
}
函数名: ftell
功 能: 返回当前文件指针
用 法: long ftell(FILE *stream);
程序例:
#include ;
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("The file pointer is at byte \
%ld\n", ftell(stream));
fclose(stream);
return 0;
}
函数名: fwrite
功 能: 写内容到流中
用 法: int fwrite(void *ptr, int size, int nitems, FILE *stream);
程序例:
#include ;
struct mystruct
{
int i;
char ch;
};
int main(void)
{
FILE *stream;
struct mystruct s;
if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */
{
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
s.i = 0;
s.ch = 'A';
fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
fclose(stream); /* close file */
return 0;
}
发表评论
-
Linux C语言常用函数 06
2012-08-31 12:17 988函数名: setbkcolor 功 能: 用调色 ... -
Linux C语言常用函数 05
2012-08-31 12:17 1087函数名: poke 功 能: 存值到一个给定存储 ... -
Linux C语言常用函数 04
2012-08-31 12:17 1236函数名: hypot 功 能: 计算直角三角形的 ... -
Linux C语言常用函数 03
2012-08-31 12:17 1276函数名: gcvt 功 能: 把浮点数转换成字符串 ... -
Linux C语言常用函数 01
2012-08-29 09:53 1915函数名: abort 功 能: 异常终止一个进程 ... -
C++笔试题
2012-08-29 09:48 8811、C++的类和C里面的struct有什么区别? 答: ... -
C 笔试面试题
2012-08-28 14:08 8761、堆栈溢出一般是由什 ... -
C,C++常见面试笔试题-04(常见)
2012-08-19 13:53 10831.求下面函数的返回 ... -
C,C++常见面试笔试题-03(高质量编程)
2012-08-19 13:50 25043 高质量编程C/C++ 一、请填写BOOL , fl ... -
C,C++常见面试笔试题-02(网络)
2012-08-19 13:46 9632网络知识 2.1 OSI和TCP ... -
C,C++常见面试笔试题-01(编程基础)
2012-08-19 13:44 26551 编程基础 1.1 基本概 ...
相关推荐
本资源提供了两个文档,一个是"linux的c函数(Word版).doc",另一个是"Linux_C_fun.pdf",它们都包含了关于Linux环境下常用C语言函数的详细资料。下面我们将深入探讨这些知识点。 1. **标准库函数**: - `stdio.h`...
在Linux系统中,C语言是基础且强大的编程...这些是Linux C语言编程中常用的一些函数,理解和熟练使用它们是编写高效、稳定程序的关键。通过实践和学习,开发者可以构建复杂的应用程序,充分利用Linux系统的强大功能。
压缩包包含:1.C语言FFT函数库FFTW,FFTW 是由麻省理工学院计算机科学实验室超级计算技术组开发的一套离散傅立叶变换(DFT)的计算库,开源、高效和标准 C 语言编写的代码使其得到了非常广泛的应用, Intel 的数学库和...
C语言函数大全是学习和参考C语言编程的关键资源,它通常包含了C语言标准库中的所有函数,以及一些常用的第三方库函数。这份"Linux C语言函数大全(htm 版,比较全)"很可能是一个HTML文档,提供了一个方便的在线查阅...
10. 其他常用函数:如`time`获取当前时间,`sleep`暂停程序执行,`getchar`和`putchar`处理单个字符输入输出等,都是日常编程中经常遇到的函数。 通过学习和实践这些C语言函数,开发者不仅可以编写出高效、可靠的...
在Linux环境中进行C语言编程时,熟练掌握常用函数库是非常重要的。本文将详细介绍Linux中C语言函数库中的字符操作函数和字符串操作函数,帮助开发者更好地理解和应用这些基础但重要的函数。 #### 二、字符操作函数 ...
本资源"Linux C语言函数大全"旨在为开发者提供一份详尽的参考指南,涵盖了Linux环境下C语言常用函数的使用和理解。 博客链接可能包含了作者对这些函数的深入解析和实例应用,这将有助于读者更好地掌握C语言在Linux...
下面,我们将详细探讨一些在Linux系统中常用的C语言函数,并解释它们的作用和使用场景。 1. **标准输入输出函数**: - `printf` 和 `scanf`:这是最基础的输入输出函数,用于格式化输出和输入数据。 - `fgets` 和...
这份"LinuxC常用函数手册"为你提供了一份详尽的参考资料,涵盖了Linux C编程中的基础到高级的函数用法。以下是一些关键的知识点: 1. **标准输入输出**: - `printf`与`scanf`:用于格式化输出和输入,是C语言中最...
1. **标准输入/输出**:`printf` 和 `scanf` 是C语言中最常用的输入输出函数,用于格式化打印和读取用户输入。在Linux中,还可以使用`fprintf`、`fscanf`、`fgets`、`fputs`等函数与文件进行交互。 2. **内存管理**...
在Linux系统中,C语言是基础且重要的编程语言,它提供了丰富的函数库来支持各种操作。本篇文章将详细探讨在Linux环境下使用的C语言函数,特别是`isalnum`、`isalpha`和`isascii`这三个函数,它们在处理字符和字符串...
- `fgets()`, `fputs()`: 读写字符串到文件中,是低级文件操作的常用函数。 2. **内存管理函数**: - `malloc()`, `calloc()`, `realloc()`: 动态内存分配,用于在运行时根据需要分配内存。 - `free()`: 释放已...
这个压缩包“Linux常用C函数速查(中文版html)”提供了对Linux下常用C语言函数的详细参考,对于初学者和经验丰富的开发者来说都是一个宝贵的资源。 C语言是一门强大的低级编程语言,它提供了直接访问硬件的能力,...
在Linux环境中,C语言是构建系统级程序,如网络通信应用的理想选择。Socket编程是C语言在实现网络通信中的核心部分,它允许不同计算机之间的进程进行数据交换。本项目涉及的"Linux C语言 socket通信聊天小程序"是一...
本资源“Linux常用C函数(中文版)”提供了一份详细的C函数参考,涵盖了在Linux环境下编程时经常会遇到的一些关键函数。这些函数是C语言标准库的一部分,同时也是Linux系统调用的基础。下面,我们将深入探讨一些重要...
Linux_c语言函数库,也称为GNU C Library,通常被称为glibc,是Linux系统上最常用的标准C函数库。它包含了ANSI C、POSIX、X/Open等标准定义的函数,以及许多针对Linux特定特性的扩展。 1. **基本输入输出**: ...
这篇文档“Linux常用C函数大全”涵盖了在Linux环境下进行C程序开发时可能会遇到的大部分常用函数,旨在提供一个清晰、全面的参考资源。下面,我们将详细讨论这些函数的主要功能和用法。 1. **标准输入输出库函数**...