设为首页 加入收藏

TOP

C语言函数整理大全五(P-S)(一)
2014-11-23 21:38:10 来源: 作者: 【 】 浏览:42
Tags:语言 函数 整理 大全 P-S
函数名: parsfnm
功 能: 分析文件名
用 法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option);
程序例:
#include
#include
#include
#include
int main(void)
{
char line[80];
struct fcb blk;
/* get file name */
printf("Enter drive and file name (no path - ie. a:file.dat) ");
gets(line);
/* put file name in fcb */
if (parsfnm(line, &blk, 1) == NULL)
printf("Error in parsfm call ");
else
printf("Drive #%d Name: s ", blk.fcb_drive, blk.fcb_name);
return 0;
}

函数名: peek
功 能: 检查存储单元
用 法: int peek(int segment, unsigned offset);
程序例:
#include
#include
#include
int main(void)
{
int value = 0;
printf("The current status of your keyboard is: ");
value = peek(0x0040, 0x0017);
if (value & 1)
printf("Right shift on ");
else
printf("Right shift off ");
if (value & 2)
printf("Left shift on ");
else
printf("Left shift off ");
if (value & 4)
printf("Control key on ");
else
printf("Control key off ");
if (value & 8)
printf("Alt key on ");
else
printf("Alt key off ");
if (value & 16)
printf("Scroll lock on ");
else
printf("Scroll lock off ");
if (value & 32)
printf("Num lock on ");
else
printf("Num lock off ");
if (value & 64)
printf("Caps lock on ");
else
printf("Caps lock off ");
return 0;
}

函数名: peekb
函数名: qsort
功 能: 使用快速排序例程进行排序
用 法: void qsort(void *base, int nelem, int width, int (*fcmp)());
程序例:
#include
#include
#include
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };

int main(void)
{
int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function);
for (x = 0; x < 5; x )
printf("%s ", list[x]);
return 0;
}
int sort_function( const void *a, const void *b)
{
return( strcmp(a,b) );
}

函数名: qsort
功 能: 使用快速排序例程进行排序
用 法: void qsort(void *base, int nelem, int width, int (*fcmp)());
程序例:
#include
#include
#include
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };

int main(void)
{
int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function);
for (x = 0; x < 5; x )
printf("%s ", list[x]);
return 0;
}
int sort_function( const void *a, const void *b)
{
return( strcmp(a,b) );
}

函数名: raise
功 能: 向正在执行的程序发送一个信号
用 法: int raise(int sig);
程序例:
#include
int main(void)
{
int a, b;
a = 10;
b = 0;
if (b == 0)
/* preempt divide by zero error */
raise(SIGFPE);
a = a / b;
return 0;
}

函数名: rand
函数名: strstr
功 能: 在串中查找指定字符串的第一次出现
用 法: char *strstr(char *str1, char *str2);
程序例:
#include
#include
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s ", ptr);
return 0;
}

函数名: strtod
功 能: 将字符串转换为double型值
用 法: double strtod(char *str, char **endptr);
程序例:
#include
#include
int main(void)
{
char input[80], *endptr;
double value;
printf("Enter a floating point number:");
gets(input);
value = strtod(input, &endptr);
printf("The string is %s the number is %lf ", input, value);
return 0;
}

函数名: strtok
功 能: 查找由在第二个串中指定的分界符分隔开的单词
用 法: char *strtok(char *str1, char *str2);
程序例:
#include
#include
int main(void)
{
char input[16] = "abc,d";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s ", p);
/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s ", p);
return 0;
}

函数名: strtol
功 能: 将串转换为长整数
用 法: long strtol(char *str, char **endptr,
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇获取文件大小代码(C语言) 下一篇C语言函数整理大全三(F-G)

评论

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