Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

(C) EOF not working in gcc

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
XST1
Apprentice
Apprentice
Posts: 163
Joined: Tue Jan 27, 2004 12:11 am

(C) EOF not working in gcc

  • Quote

Post by XST1 » Thu Mar 24, 2005 9:56 pm

I made a simple program to test EOF, yet I can't get it to function properly. Heres my code:

Code: Select all

#include <stdio.h>
main()
{
        int c;
        c = getchar();
        while (c != EOF)
        {
              c = getchar();
        }
}
I can never get out of that while loop, even when I just hit enter (which should be EOF). Anyone know why it isn't working?
Top
codergeek42
Bodhisattva
Bodhisattva
Posts: 5142
Joined: Mon Apr 05, 2004 4:44 am
Location: Anaheim, CA (USA)
Contact:
Contact codergeek42
Website

  • Quote

Post by codergeek42 » Thu Mar 24, 2005 10:20 pm

As far as I know "^D" (Ctrl+D) is the end of file control character.
~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF
Top
Mandr4ke
Apprentice
Apprentice
User avatar
Posts: 214
Joined: Thu Jul 25, 2002 8:28 pm
Location: Chicago, IL

Re: (C) EOF not working in gcc

  • Quote

Post by Mandr4ke » Sat Mar 26, 2005 9:44 am

XST1 wrote:I made a simple program to test EOF, yet I can't get it to function properly. Heres my code:

Code: Select all

#include <stdio.h>
main()
{
        int c;
        c = getchar();
        while (c != EOF)
        {
              c = getchar();
        }
}
I can never get out of that while loop, even when I just hit enter (which should be EOF). Anyone know why it isn't working?
hehe i'm pretty sure an EOF char has nothing to do with console input. EOF means end of file, and is generally used with reading files.

you want ...

Code: Select all

while ((int)c != 13) // Usually Enter
while(c != '\r' && c != '\n')  // checking both CR/LF

Code: Select all

Top
30726
Veteran
Veteran
Posts: 1501
Joined: Wed Sep 24, 2003 11:01 pm

  • Quote

Post by 30726 » Sat Mar 26, 2005 11:05 am

Like codergeek42 said, you can send an EOF to stdin with Ctrl+d. It's funny that many C tutorials/books have this little example, but yet forget to tell the reader how to send an EOF using the keyboard.
Top
Post Reply

4 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic