C语言fopen函数

来源:百度知道 编辑:UC知道 时间:2024/06/01 18:21:24
如果想给c:\program filse\1.txt里写东西
fopen应该怎么写
我试过了如果是fopen("c:\\program files\\1.txt","w")的话,程序就会在c:\program\下写一个1.txt;当然要program存在.
应该怎么办
给program files加""也不行..编译不过去...
一楼:不行,编译不过去..
二楼:也不行,还是就把文件写到program文件夹去了...
三楼:你试下,我怎么不行
#include "stdio.h"
main()
{
FILE *fp;
char *i="get in the game";

fp=fopen("c:\\program files\\1.txt","w");

fputs(i,fp);
fputc('\n',fp);
fprintf(fp,"i will become who i am");

fclose(fp);
getch();

}
这是我的程序
大家运行下,看能行不

把“program files”换成“progra~1”试试看。

#include<conio.h>
/*******************你试一下这个程序,我怎么行
#include <iostream>
#include <string>
using namespace std;

void main()
{
char *r="sadfasdfasdf";

FILE *fp; //定义指针,地址赋给它

if ((fp=fopen("c:\\asdf asdf\\1.txt","r"))==NULL)
{
printf("\nError on opening data file!");
//getch();
exit(1);
}
else cout<<"能用"<<endl;
}
/*****************
你在这里建这个文件夹
没有1.txt时输出什么?
在建1.txt后运行看看.
c:\\asdf asdf

fopen("c:\\program\ files\\1.txt","w")

文件名之间的空格也要加转译字符的

我怎么觉得应该加一个
\

用 fopen("文件名","a")追加吧