_fsopen参数说明
#include<share.h>
_fsopen 共享模式访问文件
//安全性比fopen高
_fsopen
以共享的方式打开文件或者流
FILE *_fsopen( const char *filename, const char *mode, int shflag );
filename Name of the file to open. //需要打开的文件名
mode Type of access permitted. //可以访问的类型
shflag Type of sharing allowed. //共享访问类型
_SH_COMPAT Sets Compatibility mode for 16-bit applications. //以兼容模式打开16位程序
_SH_DENYNO Permits read and write access. //充许读和写 以此模式打开类似fopen
_SH_DENYRD Denies read access to the file. //拒绝读
_SH_DENYRW Denies read and write access to the file. //拒绝读和写
_SH_DENYWR Denies write access to the file //拒绝写
#include <share.h>
int main(void)
{
FILE *f1,*f2;
char s1[256],s2[256];
//同时打开文件读取
/*f1=fopen("share.txt","r");
f2=fopen("share.txt","r");*/
f1=f2=NULL;
f1=_fsopen("share.txt","r",_SH_DENYRW);//独占文件访问wb
// f2=_fsopen("share.txt","r",_SH_DENYRW);
if (!f1)
{
perror("打开出错");
}else
{
fgets(s1,256,f1);
printf("%s \n",s1);
}
fclose(f1);
f2=fopen("share.txt","r");
if (!f2)
{
perror("打开出错");
}else
{
fgets(s2,256,f2);
printf("%s \n",s2);
}
//关掉指针
fclose(f2);
getchar();
getchar();
return 0;
}
原文链接: https://www.cnblogs.com/whzym111/p/6163594.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/245627
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!