设为首页 加入收藏

TOP

C语言函数整理大全五(P-S)(二)
2014-11-23 21:38:10 来源: 作者: 【 】 浏览:43
Tags:语言 函数 整理 大全 P-S
int base);
程序例:
#include
#include
int main(void)
{
char *string = "87654321", *endptr;
long lnumber;
/* strtol converts string to long integer */
lnumber = strtol(string, &endptr, 10);
printf("string = %s long = %ld ", string, lnumber);
return 0;
}

函数名: strupr
功 能: 将串中的小写字母转换为大写字母
用 法: char *strupr(char *str);
程序例:
#include
#include
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s ", ptr);
return 0;
}

函数名: swab
功 能: 交换字节
用 法: void swab (char *from, char *to, int nbytes);
程序例:
#include
#include
#include
char source[15] = "rFna koBlrna d";
char target[15];
int main(void)
{
swab(source, target, strlen(source));
printf("This is target: %s ", target);
return 0;
}

函数名: system
功 能: 发出一个DOS命令
用 法: int system(char *command);
程序例:
#include
#include
int main(void)
{
printf("About to spawn command.com and run a DOS command ");
system("dir");
return 0;
}

功 能: 随机数发生器
用 法: void rand(void);
程序例:
#include
#include
int main(void)
{
int i;
printf("Ten random numbers from 0 to 99 ");
for(i=0; i<10; i )
printf("%d ", rand() % 100);
return 0;
}

函数名: randbrd
功 能: 随机块读
用 法: int randbrd(struct fcb *fcbptr, int reccnt);
程序例:
#include
#include
#include
#include
int main(void)
{
char far *save_dta;
char line[80], buffer[256];
struct fcb blk;
int i, result;
/* get user input file name for dta */
printf("Enter drive and file name (no path - i.e. a:file.dat) ");
gets(line);
/* put file name in fcb */
if (!parsfnm(line, &blk, 1))
{
printf("Error in call to parsfnm ");
exit(1);
}
printf("Drive #%d File: %s ", blk.fcb_drive, blk.fcb_name);
/* open file with DOS FCB open file */
b dosptr(0x0F, &blk, 0);
/* save old dta, and set new one */
save_dta = getdta();
setdta(buffer);
/* set up info for the new dta */
blk.fcb_recsize = 128;
blk.fcb_random = 0L;
result = randbrd(&blk, 1);
/* check results from randbrd */
if (!result)
printf("Read OK ");
else
{
perror("Error during read");
exit(1);
}
/* read in data from the new dta */
printf("The first 128 characters are: ");
for (i=0; i<128; i )
putchar(buffer[i]);
/* restore previous dta */
setdta(save_dta);
return 0;
}

函数名: randbwr
功 能: 随机块写
用 法: int randbwr(struct fcp *fcbptr, int reccnt);
程序例:
#include
#include
#include
#include
int main(void)
{
char far *save_dta;
char line[80];
char buffer[256] = "RANDBWR test!";
struct fcb blk;
int result;
/* get new file name from user */
printf("Enter a file name to create (no path - ie. a:file.dat ");
gets(line);
/* parse the new file name to the dta */
parsfnm(line,&a
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇获取文件大小代码(C语言) 下一篇C语言函数整理大全三(F-G)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: