LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-08-2010, 11:25 PM   #16
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0

EOF or "end of the file" is equal to '\0' or null it is included on the stdio.h of cc
 
Old 06-08-2010, 11:28 PM   #17
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0
I use the EOF or end of the file it is equal to null when the program finds that there is no more character then the Getchar() !=EOF is false then it stops on looping
 
Old 06-08-2010, 11:29 PM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by segieif03 View Post
EOF or "end of the file" is equal to '\0' or null it is included on the stdio.h of cc
First of all, I doubt that EOF is 0, but it's not the point. I also doubt that EOF is of char type, but it's also not the point.

The point is that you are inputting characters from the keyboard, so in order to achieve the EOF condition you need to input certain keystrokes. So that was my question - what keys did you press in order to achieve EOF condition ?
 
Old 06-08-2010, 11:34 PM   #19
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0
in C language the character you input has always '/0' or null at the end example i input "are" at the memory it is separated as; on location [0] = a [1] = r [2] = e [3] = '\0' EOF is a already programed in every compiler and it is equal to '\0'
 
Old 06-08-2010, 11:35 PM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Well, I am about to leave, so enter

+keyboard +EOF +UNIX

into your favorite WEB search engine and read the matches until you find what UNIX keyboard EOF is.
 
Old 06-08-2010, 11:37 PM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
[QUOTE=segieif03;3997363]in C language the character you input has always '/0' or null at the end .../QUOTE]

Wrong; see my previous post.
 
Old 06-09-2010, 06:52 AM   #22
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0
I tried ctrl z and d but it doesnt help me
 
Old 06-09-2010, 08:18 AM   #23
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by segieif03 View Post
I tried ctrl z and d but it doesnt help me
CTRL+Z just means to STOP your application, while CTRL+d should to the trick for you. Alternatively, you could use

(a) # echo "AAA" | executable
(b) # executable < test.file

By the way, you should be careful claiming that the compiler is broken, especially if you don't use any optimizations and your test programs are that simple. I would say that in almost all cases, the error is the program and not the compiler ...

Hope that helps,
Andi
 
Old 06-09-2010, 08:50 AM   #24
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0
sorry I can't get your option sorry Im a newbie both in linux and c
 
Old 06-09-2010, 08:59 AM   #25
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by segieif03 View Post
I tried ctrl z and d but it doesnt help me
Because you ignored my suggestion - to look up on the WEB

+keyboard +EOF +UNIX
.
 
Old 06-09-2010, 09:17 AM   #26
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by Sergei Steshenko View Post
Because you ignored my suggestion - to look up on the WEB

+keyboard +EOF +UNIX
.
Sergei,

why do you always try to torture the OPs? I think you already gave a lot of hints where to search, but you shouldn't completely demotivate the OP so that he never asks a question again :-) This forum is first of all to HELP guys new to Linux and programming ...

@segieif03

If you would do a search in the WEB - as suggested by Sergei - you would find e.g. this discussion or this. I also tried to this on my Linux hosts and [CTRL d] works totally fine with your test program.

By the way, the other two options just mean:

(a) pipe the output of the 'echo' command to your process. this would then produce an EOF on the input stream

(b) the file is redirected (as input) to your program. You'll get an EOF as well

Andi
 
Old 06-09-2010, 09:19 AM   #27
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Sergei Steshenko View Post
First of all, I doubt that EOF is 0, but it's not the point. I also doubt that EOF is of char type, but it's also not the point.
EOF is certainly not 0 (nor '/0') and EOF is certainly not of char type (but that doesn't matter because the return type of getchar() is also not char).

Quote:
The point is that you are inputting characters from the keyboard, so in order to achieve the EOF condition you need to input certain keystrokes.
I thought that was ctrl D, but I'm not certain. One of the later posts seems to imply the OP tried ctrl D and it failed. Does it depend on the type of terminal window you are running the program in?

Anyway, I wanted to reinforce the point you made that the OP seems to be either ignoring or disbelieving. To make the program work, you need an end of file on the input. If the input is the keyboard, you need the right key combination to create that end of file.

Quote:
Originally Posted by ForzaItalia2006 View Post
If you would do a search in the WEB - as suggested by Sergei - you would find e.g. this discussion or this.
The information (most of the posts) in that first link is flat out wrong. The second wasn't very clear.

EOF is not the character ctrl D. EOF is not any character. There is no EOF character at the end of a Linux file.

There is an "end of file" error condition that is caused by low level input routines trying to read past the end of a file. Some routines, such as getchar() translate that condition into a return value of EOF.

The ctrl D (if it works) must be interpreted by whatever low level software is reading the keyboard. It is not written to the file (stream). It causes the software writing the stream to end it at that point (resulting in the read past end of file by the reader described above). The ctrl D (although it is the Ascii EOF character) is not an EOF when it appears in a Linux stream. It is just interpreted as a request for EOF by the software reading the keyboard.

Last edited by johnsfine; 06-09-2010 at 09:30 AM.
 
Old 06-09-2010, 09:36 AM   #28
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
[QUOTE=ForzaItalia2006;3997877]Sergei,

why do you always try to torture the OPs? I think you already gave a lot of hints where to search, but you shouldn't completely demotivate the OP so that he never asks a question again :-) This forum is first of all to HELP guys new to Linux and programming ...
...
/QUOTE]

A fishing rod is fishing rod and not a baseball bat. I.e. if I'm suggesting to find what UNIX keyboard EOF is, it should be done. Remember, it's about how to catch fish, not about bringing it on the plate.

I have very clearly written:

Quote:
The point is that you are inputting characters from the keyboard, so in order to achieve the EOF condition you need to input certain keystrokes. So that was my question - what keys did you press in order to achieve EOF condition ?
.

The OP has not yet tried to enter the needed (under UNIX) keystrokes, he entered the ones for DOS.
 
Old 06-09-2010, 10:08 AM   #29
segieif03
LQ Newbie
 
Registered: May 2010
Posts: 24

Original Poster
Rep: Reputation: 0
guys I tried ctrl D it fails. what is the right keystrokes then? I am running the program on default terminal of ubuntu
 
Old 06-09-2010, 10:09 AM   #30
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by johnsfine View Post
EOF is not the character ctrl D. EOF is not any character. There is no EOF character at the end of a Linux file.
Right! I didn't read through all the posts of the two links, just the significant ones, but you're completely right. There's no such symbol at the end of each file. And I would agree that this is very low level, I suppose as part of the read system call.

Quote:
Originally Posted by johnsfine View Post
The ctrl D (if it works) must be interpreted by whatever low level software is reading the keyboard. It is not written to the file (stream). It causes the software writing the stream to end it at that point (resulting in the read past end of file by the reader described above). The ctrl D (although it is the Ascii EOF character) is not an EOF when it appears in a Linux stream. It is just interpreted as a request for EOF by the software reading the keyboard.
Yes, sounds plausible. You could change the keystroke "producing an EOF on the stream" (the wording might not be accurate) by using the

# stty eof <keystroke, e.g. ^T for CTRL+T>

this is then doing an ioctl system call (unfortunately I don't understand the details) but this fortifies the suggestions that this is all done in the kernel?

@segieif03:

if you just call 'stty' call without any parameters, you should get a list of keystrokes whereof one should be 'eof'. My system displays 'eof=^D' and CTRL+D works, so maybe your system uses a different one?

Last edited by ForzaItalia2006; 06-09-2010 at 10:15 AM.
 
  


Reply



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
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM

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

All times are GMT -5. The time now is 05:05 PM.

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