C/C++——小编谈C语言函数那些事(26)
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. sopen函数
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;
}
2. spawnl函数
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;
}
3. srand函数
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");
fo
相关文档:
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setallpallette函数
setallpallette函数的功能是按指定方式改变所有的调色板颜色,其用法为:void far setallpallette(struct palette, fa ......
羊绒被是以山羊绒为原材料针织物而成的床上用品,依据纱线种类分成粗纺织品和精纺针织物两种,依据原材料比值可以分成纯羊绒及羊绒混纺两种经加工而成的生活用品,供暖性好,盖着舒坦,尽显高档咀嚼。 本文来源:甘肃庆阳腾达商贸 ......
某些场合,如游戏开发,工程计算中,可能需要计算反三角函数,下面是计算反正切三角函数的c源代码实例:
atan_self(double x)
{
//atan(x)=x-x^3/3+x^5/5-x^7/7+.....(-1<x<1)
//return:[-pi/2,pi/2]
double mult,sum,xx;
sum=0;
if(x==1){
return pi/4;
}
if(x==-1){
return -pi/4;
}
((x&g ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setvect函数
setvect函数的功能是设置中断矢量入口,其用法为:void setvect(int intr_num, void interrupt(*isr)());程序实例如下:
#include <st ......