加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C fopen用变量名调用?

发布时间:2020-12-16 10:33:26 所属栏目:百科 来源:网络整理
导读:以下情况是否有效? (我试图提取变量的值,并根据存储在数组中的文本创建一个文件.) #include stdio.hint main(){ char a = "a"; FILE *out; out = fopen( "%s.txt",a,"w" ); fclose(out); return 0;} 谢谢 解决方法 Is there ever a circumstance where the
以下情况是否有效? (我试图提取变量的值,并根据存储在数组中的文本创建一个文件.)

#include <stdio.h>

int main()
{
    char a = "a"; 
    FILE *out;
    out = fopen( "%s.txt",a,"w" );
    fclose(out);
    return 0;
}

谢谢

解决方法

Is there ever a circumstance where the following would work?

没有.

不要做假设!请改为阅读手册.这真的很值得.

char buf[0x100];
snprintf(buf,sizeof(buf),"%s.txt",random_string);
FILE *f = fopen(buf,"r");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读