函数名: signal
功 能: 设置某一信号的对应动作
用 法: int signal(int sig, sigfun fname);
程序例:
/* This example installs a signal handler routine for SIGFPE,
catches an integer overflow condition, makes an adjustment
to AX register, and returns. This example program MAY cause
your computer to crash, and will produce runtime errors
depending on which memory model is used.
*/
#pragma inline
#include <stdio.h>
#include <signal.h>
void Catcher(int sig, int type, int *reglist)
{
printf("Caught it!/n");
*(reglist + 8) = 3; /* make return AX = 3 */
}
int main(void)
{
signal(SIGFPE, Catcher);
asm mov ax,07FFFH /* AX = 32767 */
asm inc ax /* cause overflow */
asm into /* activate handler */
/* The handler set AX to 3 on return. If that hadn't happened,
there would have been another exception when the next 'into'
was executed after the 'dec' instruction. */
asm dec ax /* no overflow now */
asm into /* doesn't activate */
return 0;
}
函数名: sin
功 能: 正弦函数
用 法: double sin(double x);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
double result, x = 0.5;
result = sin(x);
printf("The sin() of %lf is %lf/n", x, result);
return 0;
}
函数名: sinh
功 能: 双曲正弦函数
用 法: double sinh(double x);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
double result, x = 0.5;
result = sinh(x);
printf("The hyperbolic sin() of %lf is %lf/n", x, result);
return 0;
}
函数名: sleep
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
程序例:
#include <dos.h>
#include <stdio.h>
int main(void)
{
int i;
for (i=1; i<5; i++)
{
printf("Sleeping for %d seconds/n", i);
sleep(i);
}
return 0;
}
函数名: sopen
功 能: 打开一共享文件
用 法: int sopen(char *pathname, int access, int shflag, int permiss);
程序例:
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <process.h>
#include <share.h>
#include <stdio.h>
int main(void)
{
int handle;
int status;
handle = sopen("c://autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD);
if (!handle)
{
printf("sopen failed/n");
exit(1);
}
status = access("c://autoexec.bat", 6);
if (status == 0)
printf("read/write access allowed/n");
else
printf("read/write access not allowed/n");
close(handle);
return 0;
}
函数名: sound
功 能: 以指定频率打开PC扬声器
用 法: void sound(unsigned frequency);
程序例:
/* Emits a 7-Hz tone for 10 seconds.
Your PC may not be able to emit a 7-Hz tone. */
#include <dos.h>
int main(void)
{
sound(7);
delay(10000);
nosound();
return 0;
}
函数名: spawnl
功 能: 创建并运行子程序
用 法: int spawnl(int mode, char *pathname, char *arg0,
arg1, ... argn, NULL);
程序例:
#include <process.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int result;
clrscr();
result = spawnl(P_WAIT, "tcc.exe", NULL);
if (result == -1)
{
perror("Error from spawnl");
exit(1);
}
return 0;
}
函数名: spawnle
功 能: 创建并运行子程序
用 法: int spawnle(int mode, char *pathname, char *arg0,
arg1,..., argn, NULL);
程序例:
/* spawnle() example */
#include <process.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int result;
clrscr();
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
if (result == -1)
{
perror("Error from spawnle");
exit(1);
}
return 0;
}
函数名: sprintf
功 能: 送格式化输出到字符串中
用 法: int sprintf(char *string, char *farmat [,argument,...]);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
char buffer[80];
sprintf(buffer, "An approximation of Pi is %f/n", M_PI);
puts(buffer);
return 0;
}
函数名: sqrt
功 能: 计算平方根
用 法: double sqrt(double x);
程序例:
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 4.0, result;
result = sqrt(x);
printf("The square root of %lf is %lf/n", x, result);
return 0;
}
函数名: srand
功 能: 初始化随机数发生器
用 法: void srand(unsigned seed);
程序例:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
printf("Ten random numbers from 0 to 99/n/n");
for(i=0; i<10; i++)
printf("%d/n", rand() % 100);
return 0;
}
函数名: _status87
功 能: 取浮点状态
用 法: unsigned int _status87(void);
程序例:
#include <stdio.h>
#include <float.h>
int main(void)
{
float x;
double y = 1.5e-100;
printf("Status 87 before error: %x/n", _status87());
x = y; /* <-- force an error to occur */
y = x;
printf("Status 87 after error : %x/n", _status87());
return 0;
}
函数名: stime
功 能: 设置时间
用 法: int stime(long *tp);
程序例:
#include <stdio.h>
#include <time.h>
#include <dos.h>
int main(void)
{
time_t t;
struct tm *area;
t = time(NULL);
area = localtime(&t);
printf("Number of seconds since 1/1/1970 is: %ld/n", t);
printf("Local time is: %s", asctime(area));
t++;
area = localtime(&t);
printf("Add a second: %s", asctime(area));
t += 60;
area = localtime(&t);
printf("Add a minute: %s", asctime(area));
t += 3600;
area = localtime(&t);
printf("Add an hour: %s", asctime(area));
t += 86400L;
area = localtime(&t);
printf("Add a day: %s", asctime(area));
t += 2592000L;
area = localtime(&t);
printf("Add a month: %s", asctime(area));
t += 31536000L;
area = localtime(&t);
printf("Add a year: %s", asctime(area));
return 0;
}
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s/n", string);
return 0;
}
函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s/n", destination);
return 0;
}
函数名: strchr
功 能: 在一个串中查找给定字符的第一个匹配之处/
用 法: char *strchr(char *str, char c);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d/n", c, ptr-string);
else
printf("The character was not found/n");
return 0;
}
函数名: strcmp
功 能: 串比较
用 法: int strcmp(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return 0;
}
函数名: strncmpi
功 能: 将一个串中的一部分与另一个串比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strcpy
功 能: 串拷贝
用 法: char *strcpy(char *str1, char *str2);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strcpy(string, str1);
printf("%s/n", string);
return 0;
}
函数名: strerror
功 能: 返回指向错误信息字符串的指针
用 法: char *strerror(int errnum);
程序例:
#include <stdio.h>
#include <errno.h>
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s/n", buffer);
return 0;
}
函数名: strcmpi
功 能: 将一个串与另一个比较, 不管大小写
用 法: int strcmpi(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strncmp
功 能: 串比较
用 法: int strncmp(char *str1, char *str2, int maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return(0);
}
函数名: strncmpi
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strncpy
功 能: 串拷贝
用 法: char *strncpy(char *destin, char *source, int maxlen);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strncpy(string, str1, 3);
string[3] = '/0';
printf("%s/n", string);
return 0;
}
函数名: strnicmp
功 能: 不注重大小写地比较两个串
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strnicmp(buf2, buf1, 3);
if (ptr > 0)
函数名: signal
功 能: 设置某一信号的对应动作
用 法: int signal(int sig, sigfun fname);
程序例:
/* This example installs a signal handler routine for SIGFPE,
catches an integer overflow condition, makes an adjustment
to AX register, and returns. This example program MAY cause
your computer to crash, and will produce runtime errors
depending on which memory model is used.
*/
#pragma inline
#include <stdio.h>
#include <signal.h>
void Catcher(int sig, int type, int *reglist)
{
printf("Caught it!/n");
*(reglist + 8) = 3; /* make return AX = 3 */
}
int main(void)
{
signal(SIGFPE, Catcher);
asm mov ax,07FFFH /* AX = 32767 */
asm inc ax /* cause overflow */
asm into /* activate handler */
/* The handler set AX to 3 on return. If that hadn't happened,
there would have been another exception when the next 'into'
was executed after the 'dec' instruction. */
asm dec ax /* no overflow now */
asm into /* doesn't activate */
return 0;
}
函数名: sin
功 能: 正弦函数
用 法: double sin(double x);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
double result, x = 0.5;
result = sin(x);
printf("The sin() of %lf is %lf/n", x, result);
return 0;
}
函数名: sinh
功 能: 双曲正弦函数
用 法: double sinh(double x);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
double result, x = 0.5;
result = sinh(x);
printf("The hyperbolic sin() of %lf is %lf/n", x, result);
return 0;
}
函数名: sleep
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
程序例:
#include <dos.h>
#include <stdio.h>
int main(void)
{
int i;
for (i=1; i<5; i++)
{
printf("Sleeping for %d seconds/n", i);
sleep(i);
}
return 0;
}
函数名: sopen
功 能: 打开一共享文件
用 法: int sopen(char *pathname, int access, int shflag, int permiss);
程序例:
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <process.h>
#include <share.h>
#include <stdio.h>
int main(void)
{
int handle;
int status;
handle = sopen("c://autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD);
if (!handle)
{
printf("sopen failed/n");
exit(1);
}
status = access("c://autoexec.bat", 6);
if (status == 0)
printf("read/write access allowed/n");
else
printf("read/write access not allowed/n");
close(handle);
return 0;
}
函数名: sound
功 能: 以指定频率打开PC扬声器
用 法: void sound(unsigned frequency);
程序例:
/* Emits a 7-Hz tone for 10 seconds.
Your PC may not be able to emit a 7-Hz tone. */
#include <dos.h>
int main(void)
{
sound(7);
delay(10000);
nosound();
return 0;
}
函数名: spawnl
功 能: 创建并运行子程序
用 法: int spawnl(int mode, char *pathname, char *arg0,
arg1, ... argn, NULL);
程序例:
#include <process.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int result;
clrscr();
result = spawnl(P_WAIT, "tcc.exe", NULL);
if (result == -1)
{
perror("Error from spawnl");
exit(1);
}
return 0;
}
函数名: spawnle
功 能: 创建并运行子程序
用 法: int spawnle(int mode, char *pathname, char *arg0,
arg1,..., argn, NULL);
程序例:
/* spawnle() example */
#include <process.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int result;
clrscr();
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
if (result == -1)
{
perror("Error from spawnle");
exit(1);
}
return 0;
}
函数名: sprintf
功 能: 送格式化输出到字符串中
用 法: int sprintf(char *string, char *farmat [,argument,...]);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
char buffer[80];
sprintf(buffer, "An approximation of Pi is %f/n", M_PI);
puts(buffer);
return 0;
}
函数名: sqrt
功 能: 计算平方根
用 法: double sqrt(double x);
程序例:
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 4.0, result;
result = sqrt(x);
printf("The square root of %lf is %lf/n", x, result);
return 0;
}
函数名: srand
功 能: 初始化随机数发生器
用 法: void srand(unsigned seed);
程序例:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
printf("Ten random numbers from 0 to 99/n/n");
for(i=0; i<10; i++)
printf("%d/n", rand() % 100);
return 0;
}
函数名: _status87
功 能: 取浮点状态
用 法: unsigned int _status87(void);
程序例:
#include <stdio.h>
#include <float.h>
int main(void)
{
float x;
double y = 1.5e-100;
printf("Status 87 before error: %x/n", _status87());
x = y; /* <-- force an error to occur */
y = x;
printf("Status 87 after error : %x/n", _status87());
return 0;
}
函数名: stime
功 能: 设置时间
用 法: int stime(long *tp);
程序例:
#include <stdio.h>
#include <time.h>
#include <dos.h>
int main(void)
{
time_t t;
struct tm *area;
t = time(NULL);
area = localtime(&t);
printf("Number of seconds since 1/1/1970 is: %ld/n", t);
printf("Local time is: %s", asctime(area));
t++;
area = localtime(&t);
printf("Add a second: %s", asctime(area));
t += 60;
area = localtime(&t);
printf("Add a minute: %s", asctime(area));
t += 3600;
area = localtime(&t);
printf("Add an hour: %s", asctime(area));
t += 86400L;
area = localtime(&t);
printf("Add a day: %s", asctime(area));
t += 2592000L;
area = localtime(&t);
printf("Add a month: %s", asctime(area));
t += 31536000L;
area = localtime(&t);
printf("Add a year: %s", asctime(area));
return 0;
}
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s/n", string);
return 0;
}
函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s/n", destination);
return 0;
}
函数名: strchr
功 能: 在一个串中查找给定字符的第一个匹配之处/
用 法: char *strchr(char *str, char c);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d/n", c, ptr-string);
else
printf("The character was not found/n");
return 0;
}
函数名: strcmp
功 能: 串比较
用 法: int strcmp(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return 0;
}
函数名: strncmpi
功 能: 将一个串中的一部分与另一个串比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strcpy
功 能: 串拷贝
用 法: char *strcpy(char *str1, char *str2);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strcpy(string, str1);
printf("%s/n", string);
return 0;
}
函数名: strerror
功 能: 返回指向错误信息字符串的指针
用 法: char *strerror(int errnum);
程序例:
#include <stdio.h>
#include <errno.h>
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s/n", buffer);
return 0;
}
函数名: strcmpi
功 能: 将一个串与另一个比较, 不管大小写
用 法: int strcmpi(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strncmp
功 能: 串比较
用 法: int strncmp(char *str1, char *str2, int maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return(0);
}
函数名: strncmpi
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
用 法: int strncmpi(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strncpy
功 能: 串拷贝
用 法: char *strncpy(char *destin, char *source, int maxlen);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strncpy(string, str1, 3);
string[3] = '/0';
printf("%s/n", string);
return 0;
}
函数名: strnicmp
功 能: 不注重大小写地比较两个串
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strnicmp(buf2, buf1, 3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}