易截截图软件、单文件、免安装、纯绿色、仅160KB

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++——小编谈C语言函数那些事(21)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.     setfillpatterne函数
setfillpatterne函数的功能是选择用户定义的填充模式,其用法为:void far setfillpattern(char far *upattern, int ......

反正切三角函数的c源代码

某些场合,如游戏开发,工程计算中,可能需要计算反三角函数,下面是计算反正切三角函数的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++——小编谈C语言函数那些事(22)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.    setmem函数
setmem函数的功能是存值到存储区,其用法为:void setmem(void *addr, int len, char value);程序实例如下:
#include <stdio.h& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号