C语言文件路径设置

C语言文件路径设置,第1张

C语言中指定文件路径的三种方法

方法一:当前工程下的文件

fopen("demo.txt","rt")

方法二:当前工程下的 test文件夹 中文件

fopen(".\\test\\demo.txt","rt")

方法三:绝对路径,D盘下project文件夹中的文件

fopen("d:\\project\\demo.txt","rt")

用于保存文件的目录要事先存在!否则会输出错误信息!

//---------------------------------------------------------------------------

#include

#include

#define

fppath

"c:\\vcf\\"

/*文件的保存目录,末尾的斜杠不可省略*/

int

main(void)

{

file

*fp

char

fn[255]

int

i

for

(i

=

1

i<=1000

i++)

{

sprintf(fn,"%s%d.vcf",fppath,i)

fp=fopen(fn,"w")

if

(!fp)

{

fprintf(stderr,"file

error(%s)\n",fn)

continue

}

fputs("begin:vcard\nversion:2.1",fp)

fprintf(fp,"ncharset=utf-8encoding=quoted-printable:%d\n",i)

fprintf(fp,"telcell:%d\n",i)

fputs("end:vcard",fp)

fclose(fp)

}

return

0

}

//---------------------------------------------------------------------------


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/tougao/11486230.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存