[SOLVED] no output on C programming using gcc compiler.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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 ?
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'
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 ...
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
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
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.