需要帮忙.. [英] need help..

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

问题描述

< 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

推荐答案

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


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

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