From: php-coder <php-coder@altlinux.ru>
To: community@altlinux.ru
Subject: [Comm] [BUG] feof() и дублирование последней строки
Date: Tue, 7 Jun 2005 20:37:36 +0700
Message-ID: <20050607133736.GA4274@mycomp.mydomain> (raw)
Доброго времени суток сообщество!
Вот заметил тут, что простейший примерчик на Сях работает очень
странно, и даже, прямо таки скажем, неожиданно. Дело в том, что
считывается лишняя строчка, т.е. последння строка файла по неведомой
мне причине считывается дважды.
[c0der@mycomp ~]$ cat test.c
#include <stdio.h>
int main()
{
char str[100];
FILE *fd;
fd = fopen("test.txt", "r");
while(! (feof(fd))) {
fscanf(fd, "%s", str);
printf("%s\n", str);
}
fclose(fd);
return 0;
}
[c0der@mycomp ~]$ cat test.txt
1
2
3
[c0der@mycomp ~]$ ./test
1
2
3
3
Объясните что происходит, пожалуйста.. :-)
Пока использую немного переделанную конструкцию:
...
fd = fopen("test.txt", "r");
fscanf(fd, "%s", str);
do {
printf("%s\n", str);
fscanf(fd, "%s", str);
}while(! (feof(fd)));
fclose(fd);
...
P.S. Проверил сегодня этот пример на Visual C++ 6.0 -- все работает
как и должно. Окончательно укоренился в мысли, что это бага. Если да,
то на какой пакет вешать?
Спасибо за внимание!
--
+ php-coder
+ php-coder[at]altlinux[dot]ru
next reply other threads:[~2005-06-07 13:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-07 13:37 php-coder [this message]
2005-06-07 13:55 ` [Comm] [BUG] feof() Х ДСАКХПНБЮМХЕ ОНЯКЕДМЕИ ЯРПНЙХ Alexey Rusakov
2005-06-07 13:59 ` [Comm] [BUG] feof() и дублирование последней строки Dmitry V. Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050607133736.GA4274@mycomp.mydomain \
--to=php-coder@altlinux.ru \
--cc=community@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git