• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

需要帮忙..

用户头像
it1352
帮助1

问题说明

< code>

line = 1;

while(!feof(infile))

{

if(line = 2)

{

fgets(name,25,infile);

}

否则if(line = 3)

{

fgets(地址,80,infile);

strcat(tempaddress,address);

if(strcmp(address,"?")== 0)

{

line = 4;

}

}

否则if(line = 4)

{

fgets(yearofbirth,5,如果(行= 5)

{

fgets(telno,15, inf b)

line ;

printf("%s%s%s%s",name,地址,yearofbirth,telno);

addRecord(rptrp,name,address,atoi(yearofbirth),telno

);


}

< / code>


我想知道是否有人可以帮助我。出于某种原因,这个while循环

并没有更新。 line总是设置为1.我正在尝试获取每一行

并将其存储在每个数组中。

发表于: http://www.groupsrv.com


发表于Vianet.com Premium Usenet新闻组服务

---------------------------------------- ------------------

**速度**保留**完成**匿名**

- -------------------------------------------------- ------
http://www.usenet.com

<code>
line = 1;
while( !feof( infile ) )
{
if( line = 2 )
{
fgets( name, 25, infile );
}
else if( line = 3 )
{
fgets( address, 80, infile );
strcat( tempaddress, address );
if( strcmp( address, "?" ) == 0 )
{
line = 4;
}
}
else if( line = 4 )
{
fgets( yearofbirth, 5, infile );
}
else if( line = 5 )
{
fgets( telno, 15, infile );
}

line ;
printf( "%s%s%s%s", name, address, yearofbirth, telno );
addRecord( rptrp , name, address, atoi(yearofbirth), telno
);

}
</code>

I wonder if someone can help me out. For some reason, this while loop
doesn''t update. line is always set to 1. i''m trying to get each line
and store it in each array.
Posted at: http://www.groupsrv.com

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

正确答案

#1
slickn_sly写道:
slickn_sly wrote:
line = 1;
while(!feof(infile) )
^^^^^^^^^^^^^^^^^^^^^^^^

这是一个错误;有关详细信息,请查看常见问题解答,您的C教科书或任何大型的先前线程的b
。 {
if(line = 2)
line = 1;
while( !feof( infile ) ) ^^^^^^^^^^^^^^^^^^^^^^^^
This is a mistake; check the FAQ, your C textbook, or any of a large
number of previous threads for details. {
if( line = 2 )



^^^^^^^^^^^^

此以及所有后续条件如:它几乎肯定是一个错误的b $ b错误。 ''=''是赋值运算符; ''==''是平等的

比较操作。


^^^^^^^^^^^^
This, and all subsequent conditions like it, are almost certainly a
mistake. ''='' is the assignment operator; ''=='' is the equality
comparison operatior.

Martin Ambuhl写道:
Martin Ambuhl wrote:
slickn_sly写道:

.... snip ...
slickn_sly wrote:
.... snip ...
{
if(line = 2)
{
if( line = 2 )


^^^^^^^ ^^^^^
这个,以及所有后续条件,几乎可以肯定是一个错误。 ''=''是赋值运算符; ''==''是平等的比较操作。


^^^^^^^^^^^^
This, and all subsequent conditions like it, are almost certainly
a mistake. ''='' is the assignment operator; ''=='' is the equality
comparison operatior.




你可以通过简单地培养
$ b来轻松避免$ b写作的习惯:


if(2 == line)...


即将常数放在第一位。


-

"如果你想通过groups.google.com发布一个后续内容,请不要使用

破损的" ;回复"链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson



Which you can easily avoid at all times by simply cultivating the
habit of writing:

if (2 == line) ...

i.e. put the constant first.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson



" CBFalconer" < CB ******** @ yahoo.com>在消息中写道

news:42 *************** @ yahoo.com ...

"CBFalconer" <cb********@yahoo.com> wrote in message
news:42***************@yahoo.com...
Martin Ambuhl写道:
Martin Ambuhl wrote:
slickn_sly写道:
slickn_sly wrote:


... snip ...


... snip ...

{
if(line = 2 )
{
if( line = 2 )


^^^^^^^^^^^^
这个,以及所有后续条件,几乎可以肯定是一个错误。 ''=''是赋值运算符; ''==''是平等的比较操作。


^^^^^^^^^^^^
This, and all subsequent conditions like it, are almost certainly
a mistake. ''='' is the assignment operator; ''=='' is the equality
comparison operatior.



通过简单地培养写作的习惯,你可以随时轻松避免:

if(2 == line)...

即把常数放在第一位。



Which you can easily avoid at all times by simply cultivating the
habit of writing:

if (2 == line) ...

i.e. put the constant first.




或自OP以来使用多个常量,一个更简洁的方法是使用switch()语句来使用


Allan



Or since the OP is using multiple constants, a neater approach would be to
use a switch() statement.
Allan

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhecgbfa
系列文章
更多 icon
同类精品
更多 icon
继续加载