需要帮忙..
问题说明
< 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
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhecgbfa
-
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
复制文件夹/文件而不修改属性?
it1352 07-15 -
为什么字符'^'被Python Popen忽略 - 在Popen Windows转义'^'字符?
it1352 08-07