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 ......
许多编程语言中的调用函数的两种方法是按值调用(call-by-value)和按引用调用(call-by-reference)。
参数按值调用传递时,生成参数值副本并且传给被调用函数,副本的改变并不影响调用者的原始变量值,这样就可以防止意外的副作用影响开发正确,可靠的系统。按值调用的一个缺点是,如果传递较大的数据项,则复制这个数 ......
题目:输入三个字符串a,b和c,将a中b的第一次出现替换为c。
代码:
#include <iostream.h>
#include <string.h>
/*字符串替换,第一个参数为原串,第二个参数为要匹配的子串
第三个参数为要替换的第一个子串中包含第二个子串的部分*/
char *strReplace(char *str1,char *str2,char *str3);
void main() ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setwritemode函数
setwritemode函数的功能是设置图形方式下画线的输出模式,其用法为:void far setwritemode(int mode);程序实例如下:
#include < ......