fgets出错 [英] Error with fgets

查看:109
本文介绍了fgets出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试多年来第一次使用c并在fgets中吹嘘。


我创建了这个非常简单的程序仍然会产生错误:

#include< stdio.h>


int main(int argc,char * argv [])

{

FILE * fp1;

char * text1;


fgets(text1,150,stdin);

fputs (text1,stdout);

return(0);

}


错误是指令处于 0x78022901"

" 0x00000003"中引用的内存。存储器不能被写入。

输入一些文字并按回车后我就明白了。


我正在使用gcc。

Trying to use c for the first time in years and blowing out in fgets.

I created this very simple program which still produces the error:

#include <stdio.h>

int main(int argc, char *argv[])
{
FILE *fp1;
char *text1;

fgets(text1,150,stdin);
fputs(text1,stdout);
return(0);
}

The error is "The instruction at "0x78022901" referenced memory at
"0x00000003". The memory could not be "written"." I get it after
typing in some text and hitting enter.

I''m using gcc.

推荐答案

blindsey写道:
blindsey wrote:

多年来第一次尝试使用c并在fgets中吹嘘。


我创建了这个非常简单的程序仍然会产生错误:


#include< stdio.h>


int main(int argc,char * argv [])

{

FILE * fp1;

char * text1;


fgets(text1,150,stdin);

fputs(text1,stdout);

return(0);
Trying to use c for the first time in years and blowing out in fgets.

I created this very simple program which still produces the error:

#include <stdio.h>

int main(int argc, char *argv[])
{
FILE *fp1;
char *text1;

fgets(text1,150,stdin);
fputs(text1,stdout);
return(0);



顺便说一句,在这个退货声明中你不需要括号。

BTW, you don''t need parentheses in this return statement.


}
}

http://c-faq.com/aryptr/aryptr2 .html


-

彼得

http://c-faq.com/aryptr/aryptr2.html

--
Peter


4月15日,7日: 06 * pm,Peter Nilsson< ai ... @ acay.com.auwrote:
On Apr 15, 7:06*pm, Peter Nilsson <ai...@acay.com.auwrote:

blindsey写道:
blindsey wrote:

尝试多年来第一次使用c并且在fgets中爆发。
Trying to use c for the first time in years and blowing out in fgets.


我创建了这个非常简单的程序,它仍然产生错误:
I created this very simple program which still produces the error:


#include< stdio.h>
#include <stdio.h>


* * * * int main(int argc,char * argv [])

* * * * {

* * * * * FILE * fp1;

* * * * * char * text1;
* * * *int main(int argc, char *argv[])
* * * *{
* * * * *FILE *fp1;
* * * * *char *text1;


* * * * * fgets(text1,150,stdin);

* * * * * fputs(text1 ,stdout);

* * * * * return(0);
* * * * *fgets(text1,150,stdin);
* * * * *fputs(text1,stdout);
* * * * *return(0);



BTW,你不需要在这个返回语句中使用括号。


BTW, you don''t need parentheses in this return statement.


* * * * }
* * * *}



* http://c-faq.com/aryptr/aryptr2.html


-

Peter


*http://c-faq.com/aryptr/aryptr2.html

--
Peter



谢谢!


啊,过去我从来没有...


就像我说的,已经有一段时间了。


Thanks!

Ah, in the old days I never would have ...

Like I said, it had been a while.




" blindsey" < bl ****** @ dsicdi.com写信息

新闻:ff ************************ ********** @ p25g2000 hsf.googlegroups.com ...

"blindsey" <bl******@dsicdi.comwrote in message
news:ff**********************************@p25g2000 hsf.googlegroups.com...

多年来第一次尝试使用c并吹嘘fgets。


我创建了这个非常简单的程序仍然会产生错误:


#include< stdio.h>


int main(int argc,char * argv [])

{

FILE * fp1;

char *文本1;
Trying to use c for the first time in years and blowing out in fgets.

I created this very simple program which still produces the error:

#include <stdio.h>

int main(int argc, char *argv[])
{
FILE *fp1;
char *text1;



你应该在这里初始化text1,指向一个至少150

字符的数组,或者使用malloc分配至少150个字符。


否则它将包含任意(和非法)地址。例如

0x00000003。

You should initialise text1 here, to point to an array of at least 150
chars, or using malloc to allocate at least 150 chars.

Otherwise it will contain an arbitrary (and illegal) address. Such as
0x00000003.


fgets(text1,150,stdin);

fputs(text1,stdout );

返回(0);

}


错误是指令处于0x78022901

" 0x00000003"中引用的内存。存储器不能被写入。

输入一些文字然后按回车后我就明白了。


我正在使用gcc。
fgets(text1,150,stdin);
fputs(text1,stdout);
return(0);
}

The error is "The instruction at "0x78022901" referenced memory at
"0x00000003". The memory could not be "written"." I get it after
typing in some text and hitting enter.

I''m using gcc.



-

巴特

--
Bart


这篇关于fgets出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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