LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2013, 12:27 PM   #1
batman4
Member
 
Registered: Jul 2012
Posts: 47

Rep: Reputation: Disabled
c program: how can it be identified when the control reaches eof .


this is the code

Code:
#include<stdio.h>
main(){
int c,count=0;
if((c=getchar())=!EOF)
printf("process");

printf("end");

}
In what case will it print end .
if we press ctrl+d/ ctrl+c ,it should first print "end"
Please explain me in which case my control will be in else condition.
 
Old 02-03-2013, 02:36 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Well, your code has no loop, so you'll always fall though to the "end."
Perhaps you meant
Code:
$ cat temp.c
#include<stdio.h>
main(){
  int c,count=0;
  while ((c=getchar()) != EOF)
    printf("process c=\"%c\"\n",c);

  printf("end\n");

}
$ echo -n abcd | ./temp 
process c="a"
process c="b"
process c="c"
process c="d"
end
Note: ^C will terminate the execution of the whole program, not end the input. ^D is what you want.
Note2: The getchar function will read the '\n' at the end of each input line, hence the -n option to the echo command in the sample output, above.
 
  


Reply

Tags
programing



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it posible to control a program using your own program? danoc93 Programming 1 07-06-2012 04:03 AM
Anyone here program with .NET 2.0? I need some help with a control. scheidel21 Programming 2 06-13-2008 01:09 PM
How to logout under program control? sprezzatura Programming 1 04-17-2006 08:49 AM
Perl program control MWFlint Programming 4 12-08-2004 12:59 PM
How to fully control a program within another program marri Programming 5 07-28-2004 09:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration