无法创建用于写入的文件 [英] Cannot create file for write

查看:67
本文介绍了无法创建用于写入的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试创建一个文件来写:


FILE * List_of_Files;

char * List =" List_of_Files;


if((List_of_Files = fopen(List," w"))== NULL)

{

fprintf(stderr,不能写文件);

}


我不明白为什么它没有打开文件进行写作。请帮忙。


谢谢,

Marcia

Hi,

I am trying to create a file for writing:

FILE * List_of_Files;
char * List = "List_of_Files;

if((List_of_Files = fopen(List, "w")) == NULL)
{
fprintf(stderr, "Cannot write file");
}

I don''t understand why it does not open the file for writing. Please help.

Thanks,
Marcia

推荐答案

Marcia Hon< ;豪** @ rogers.com>潦草地写道:
Marcia Hon <ho**@rogers.com> scribbled the following:

我正在尝试创建一个文件来写:
FILE * List_of_Files;
char * List =" List_of_Files;
if((List_of_Files = fopen(List," w"))== NULL)
{f / / fprintf(stderr,无法写文件);
}
我不明白为什么它不打开文件进行写作。请帮忙。
Hi, I am trying to create a file for writing: FILE * List_of_Files;
char * List = "List_of_Files; if((List_of_Files = fopen(List, "w")) == NULL)
{
fprintf(stderr, "Cannot write file");
} I don''t understand why it does not open the file for writing. Please help.




这段代码甚至无法编译。如果您希望我们有希望分析它,请告诉我们您的真实代码。


-

/ - - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \

\\ \\ - http://www.helsinki.fi/~palaste - -------------------规则! -------- /

冰淇淋销售不知何故导致溺水:两者都发生在夏季。

- Antti Voipio& Arto Wikla



This code doesn''t even compile. Please show us your real code if you
want us to have any hope of analysing it.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Ice cream sales somehow cause drownings: both happen in summer."
- Antti Voipio & Arto Wikla


" Marcia Hon" <豪** @ rogers.com>在消息中写道

新闻:zS ****************** @ twister01.bloor.is.net.c able.rogers.com ...
"Marcia Hon" <ho**@rogers.com> wrote in message
news:zS******************@twister01.bloor.is.net.c able.rogers.com...


我正在尝试创建一个文件来写:


阅读''fopen()'的文档。你正在传递

错误的论点。你的代码甚至不应该编译。


#include< stdio.h> / *这个头文件声明了

标准的i / o函数(例如''fopen()'')

可见,所以编译器可以检查

你已经传递了正确的数字和

类型的参数。 * /


int main(无效)

{

FILE * List_of_Files;
char * List =" List_of_Files;


char filename [] =" the_name_of_my_file" ;; / *改为你的

实际文件名是* /

if((List_of_Files = fopen(List," w"))== NULL)


if((List_of_Files = fopen(filename," w"))== NULL)/ * first arg可能是

字面值
$ b如果需要$ b字符串* /

{
fprintf(stderr,不能写文件);
}

我不是理解为什么它不打开文件进行写作。请帮忙。
Hi,

I am trying to create a file for writing:
Read the documentation of ''fopen()''. You''re passing the
wrong arguments. Your code should not even compile.

#include <stdio.h> /* this header makes the declaration of the
standard i/o functions (e.g. ''fopen()'')
visible, so the compiler can check that
you''ve passed the correct number and
types of arguments. */

int main(void)
{
FILE * List_of_Files;
char * List = "List_of_Files;
char filename[] = "the_name_of_my_file"; /* change to whatever your
actual file name is */

if((List_of_Files = fopen(List, "w")) == NULL)
if((List_of_Files = fopen(filename, "w")) == NULL) /* first arg could be a
literal
string if desired */
{
fprintf(stderr, "Cannot write file");
}

I don''t understand why it does not open the file for writing. Please help.




我不明白为什么你没有发布实际的(完整的,

可编译的)代码'给你带来麻烦。 :-)


此外,''FILE *''类型只能指定一个* single *文件(技术上,

称为''stream' ')一次。我认为您的标识符''List_of_Files''

非常具有误导性。


-Mike



I don''t understand why you didn''t post the actual (complete,
compilable) code that''s giving you trouble. :-)

Also, the ''FILE*'' type can only designate a *single* file (technically,
called a ''stream'') at a time. I think your identifier ''List_of_Files''
is quite misleading.

-Mike


2004年2月9日星期一01:20:04 +0000,Yarblek de Logh写道:
On Mon, 09 Feb 2004 01:20:04 +0000, Yarblek de Logh wrote:
嗨:

我只是C的初学者语言,但我想我已经看到你失败了:

你必须把文件名放在引号中。以这种方式尝试:

FILE * List_of_Files = fopen(" List",w);

如果我的英语不太好,请抱歉。
Hi:

I''m only a beginner in C language, but I think I''ve seen your fail:

You must put the file name in inverted commas. Try it in this way:

FILE *List_of_Files = fopen ("List","w");

Sorry if my English is not so good.




如果她想打开一个名为List的文件,那将是正确的,但是列表

实际上是文件名的char *。这些引号就在她的位置,即
为这个指针指定一个字符串:


char * List =" List_of_Files";


除了缺失的最终报价中该行的原始内容(

表示Marcia发布的内容不是实际代码.Marcia在
$ b $阅读b请问底部。)程序看起来很好。她可能想看看

" errno"找出fopen()失败的原因。
Marcia:

你会得到一个更好的回应你做一个显示
$ b $的小程序b问题,然后编译并运行程序,然后在您的帖子中剪切并粘贴源

,以便我们都有一个可编译的问题示例。

经常你'实际上你会自己弄清楚问题的准备工作

例子


-

NPV

大字印刷品,小字体带走

Tom Waits - 向上走吧



That would be coorrect if she wanted to open a file called List, but list
is actually a char* to the filename. The quotes goes in the line where she
assigns a string to this pointer:

char * List = "List_of_Files";

Beside the missing final quote int the original of that line (which
indicates that what Marcia posted wasn''t the actual code. Marcia read at
the bottom please.) the program looks fine. She might want to look at
"errno" to figure out why fopen() fails.
Marcia:
You''ll get a better response of you make a tiny program displaying the
problem, then compile and run the program, then cut and paste the source
in your post so that we all have a compileable example of the problem.
Often you''ll actually figure out the problem yourself wile preparing your
example

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up


这篇关于无法创建用于写入的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆