?
Solved

C program does not terminate

Posted on 2003-02-20
5
Medium Priority
?
228 Views
Last Modified: 2010-04-17
Iam using turbo Cv3.0 .It does not recognise the constant EOF.For example consider following example.
#include <stdio.h>
void main()
{
int c ;
int count ;

while ( ( c = getchar() ) != EOF )
   count ++ ;

printf( "%d characters\n" , count ) ;
}

When I compile the program and run it generates the required output ,but the program does not terminate.
0
Comment
Question by:purtutu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:gj62
ID: 7987579
You said it generates the required output - that would be the printf?  If so, your loop has exited and EOF was recognized...  What do you mean it hasn't terminated?
0
 
LVL 11

Accepted Solution

by:
dimitry earned 100 total points
ID: 7987885
First you need to initialize your counter.
int count = 0;
Second, if you try to get EOF character from keyboard then it is CTRL-Z.
0
 
LVL 1

Assisted Solution

by:irisex
irisex earned 100 total points
ID: 7989540
Typically, control-d or ASCII EOT, generates an EOF, from a terminal. On receiving EOF, a read immediately passes any bytes of data it holds to the process without waiting for a new-line, and discards the EOF. If EOF occurred at the beginning of a line, a read holds no bytes of data, and returns a byte count of zero, the standard end-of-file indication.

Substitute EOF by 4. If it does not work, by 0.

And don't forget to initialize your counter (int count=0;)
0
 

Author Comment

by:purtutu
ID: 7993673
THanks a bunch for the fast response.
0
 
LVL 3

Expert Comment

by:FaithRaven
ID: 9307885
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split points to dimitry & irisex
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

FaithRaven
EE Cleanup Volunteer
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question