Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我理解 C 中 fopen 的语法是
fp = fopen ("file2.txt", "r");
我的问题是,如果我想要打开一个 char 字符串中的 txt 文件路径,我可以做
char str[100]; FILE *fp; sprintf(str, "\room%d.txt", 2); fp = fopen (str, "r");
还是有更好的方法来做到这一点?
只要最终进入str的路径是操作系统识别的路径,它就可以正常工作
str
是的你可以。但是您应该使用要打开的txt文件的正确绝对路径或相对路径。