找回密码

碧海潮声大学生网

楼主: 墙角野猫
打印 上一主题 下一主题

c语言函数大全

[复制链接]
51#
 楼主| 发表于 2006-7-12 23:01 | 只看该作者
函数名: country
功 能: 返回与国家有关的信息
用 法: struct COUNTRY *country(int countrycode, struct country *country);
程序例:
#include
#include
#define USA 0
int main(void)
{
struct COUNTRY country_info;
country(USA, &country_info);
printf("The currency symbol for the USA is: %s
",
country_info.co_curr);
return 0;
}
52#
 楼主| 发表于 2006-7-12 23:01 | 只看该作者
函数名: cprintf
功 能: 送格式化输出至屏幕
用 法: int cprintf(const char *format[, argument, ...]);
程序例:
#include
int main(void)
{
/* clear the screen */
clrscr();
/* create a text window */
window(10, 10, 80, 25);
/* output some text in the window */
cprintf("Hello world\r
");
/* wait for a key */
getch();
return 0;
}
53#
 楼主| 发表于 2006-7-12 23:02 | 只看该作者
函数名: cputs
功 能: 写字符到屏幕
用 法: void cputs(const char *string);
程序例:
#include
int main(void)
{
/* clear the screen */
clrscr();
/* create a text window */
window(10, 10, 80, 25);
/* output some text in the window */
cputs("This is within the window\r
");
/* wait for a key */
getch();
return 0;
}
54#
 楼主| 发表于 2006-7-12 23:02 | 只看该作者
函数名: _creat creat
功 能: 创建一个新文件或重写一个已存在的文件
用 法: int creat (const char *filename, int permiss);
程序例:
#include
#include
#include
#include
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* change the default file mode from text to binary */
_fmode = O_BINARY;
/* create a binary file for reading and writing */
handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);
/* write 10 bytes to the file */
write(handle, buf, strlen(buf));
/* close the file */
close(handle);
return 0;
}
55#
 楼主| 发表于 2006-7-12 23:03 | 只看该作者
函数名: creatnew
功 能: 创建一个新文件
用 法: int creatnew(const char *filename, int attrib);
程序例:
#include
#include
#include
#include
#include
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* attempt to create a file that doesn't already exist */
handle = creatnew("DUMMY.FIL", 0);
if (handle == -1)
printf("DUMMY.FIL already exists.
");
else
{
printf("DUMMY.FIL successfully created.
");
write(handle, buf, strlen(buf));
close(handle);
}
return 0;
}
56#
 楼主| 发表于 2006-7-12 23:04 | 只看该作者
函数名: creattemp
功 能: 创建一个新文件或重写一个已存在的文件
用 法: int creattemp(const char *filename, int attrib);
程序例:
#include
#include
#include
int main(void)
{
int handle;
char pathname[128];
strcpy(pathname, "\\");
/* create a unique file in the root directory */
handle = creattemp(pathname, 0);
printf("%s was the unique file created.
", pathname);
close(handle);
return 0;
}
57#
 楼主| 发表于 2006-7-12 23:04 | 只看该作者
函数名: cscanf
功 能: 从控制台执行格式化输入
用 法: int cscanf(char *format[,argument, ...]);
程序例:
#include
int main(void)
{
char string[80];
/* clear the screen */
clrscr();
/* Prompt the user for input */
cprintf("Enter a string with no spaces:");
/* read the input */
cscanf("%s", string);
/* display what was read */
cprintf("\r
The string entered is: %s", string);
return 0;
}
58#
 楼主| 发表于 2006-7-12 23:05 | 只看该作者
函数名: ctime
功 能: 把日期和时间转换为字符串
用 法: char *ctime(const time_t *time);
程序例:
#include
#include
int main(void)
{
time_t t;
time(&t);
printf("Today's date and time: %s
", ctime(&t));
return 0;
}
59#
 楼主| 发表于 2006-7-12 23:05 | 只看该作者
函数名: ctrlbrk
功 能: 设置Ctrl-Break处理程序
用 法: void ctrlbrk(*fptr)(void);
程序例:
#include
#include
#define ABORT 0
int c_break(void)
{
printf("Control-Break pressed. Program aborting ...
");
return (ABORT);
}
int main(void)
{
ctrlbrk(c_break);
for(;;)
{
printf("Looping... Press to quit:
");
}
return 0;
}
60#
 楼主| 发表于 2006-7-12 23:06 | 只看该作者
函数名: delay
功 能: 将程序的执行暂停一段时间(毫秒)
用 法: void delay(unsigned milliseconds);
程序例:
/* Emits a 440-Hz tone for 500 milliseconds */
#include
int main(void)
{
sound(440);
delay(500);
nosound();
return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表