|
#211
|
|
|
|
|
> On Mon, 29 Sep 2008 15:16:56 +0100, Ben Bacarisse wrote:
> Please do, or mark it like this: > > #ifdef DEBUG > ... > #endif > > so we know it is not what you are really trying to do. okay. > No. A function takes what it must due to its design. > get_single_word() needs a char ** because its job is to set a char * > that "does not belong to it". It is passed a pointer to the char * > that is must set: get_single_word(char **); > > Giving get_input() a char *** parameter does not mean that this must be > passed to get_single_word. You get to say what you pass! Thanks so much for the technical advice. I will take some time to write some pseudo code again to get done with the design of the functions first. I will make a new post with my new pseudo code and discussion of function design. |
|
|
|
#212
|
|
|
|
|
> On Mon, 29 Sep 2008 12:28:59 +0000, James Kuyper wrote:
> What does that have to do with it? what you pass to feof() and ferror() > is not the value returned by the I/O function. What you pass it is the > FILE* associated with the stream that you are using the I/O function on. > The getchar() function is exactly equivalent to getc(stdin); it's > provided as a separate function from getc() only for convenience. All > you need to do is check feof(stdin) and ferror(stdin). I can't, that input character is needed by the program, hence I use ch to store it. If i use feof(stdin) then I will loose the input and will get only the integer vale returned by feof or ferror. The input character is needed because we are storing them |
|
#213
|
|
|
|
|
On 30 Sep, 06:17, arnuld <sunr...@invalid.address> wrote:
> > On Mon, 29 Sep 2008 12:28:59 +0000, James Kuyper wrote: > > What does that have to do with it? what you pass to feof() and ferror() > > is not the value returned by the I/O function. What you pass it is the > > FILE* associated with the stream that you are using the I/O function on. > > The getchar() function is exactly equivalent to getc(stdin); it's > > provided as a separate function from getc() only for convenience. All > > you need to do is check feof(stdin) and ferror(stdin). > > I can't, that input character is needed by the program, hence I use ch to > store it. If i use feof(stdin) then I will loose the input and will get > only the integer vale returned by feof or ferror. I'm baffled. Why will you "lose the input"? What does this mean. > The input character is > needed because we are storing them what? int read_char_and_check (FILE* f) { char ch; ch = getc (f); if (ch == EOF) { if (feof(f)) printf ("end-of-file\n"); else printf ("error reading file\n"); } return ch; } |
|
#214
|
|
|
|
|
arnuld wrote:
>> On Mon, 29 Sep 2008 12:28:59 +0000, James Kuyper wrote: > >> What does that have to do with it? what you pass to feof() and ferror() >> is not the value returned by the I/O function. What you pass it is the >> FILE* associated with the stream that you are using the I/O function on. >> The getchar() function is exactly equivalent to getc(stdin); it's >> provided as a separate function from getc() only for convenience. All >> you need to do is check feof(stdin) and ferror(stdin). > > I can't, that input character is needed by the program, hence I use ch to > store it. If i use feof(stdin) then I will loose the input and will get > only the integer vale returned by feof or ferror. The input character is > needed because we are storing them What are you talking about? Just replace feof(ch) with feof(stdin); there's no reason why doing so would require you to make any changes to the line where you write ch=getchar(). |
|
#215
|
|
|
|
|
On Sep 30, 11:12 am, Nick Keighley <nick_keighley_nos>
wrote: > > int read_char_and_check (FILE* f) > { > char ch; > ch = getc (f); That's implementation defined, if char is signed and EOF < SCHAR_MIN or if a value greater than SCHAR_MAX is returned. > if (ch == EOF) > { > if (feof(f)) > printf ("end-of-file\n"); > else > printf ("error reading file\n"); It doesn't have to be an error. Assuming char is unsigned, EOF == -1, you'd get the same results for reading UCHAR_MAX and EOF. > } > return ch; > } It's possible that this return value is never equal to EOF, even if ch == EOF |
|
#216
|
|
|
|
|
On 30 Sep, 09:12, Nick Keighley <nick_keighley_nos>
wrote: > On 30 Sep, 06:17, arnuld <sunr...@invalid.address> wrote: >> > I'm baffled. Why will you "lose the input"? What does this mean. >> what? > > int read_char_and_check (FILE* f) > { > char ch; int ch; /* doh! */ [..] |
|
#217
|
|
|
|
|
On Tue, 30 Sep 2008 10:17:10 +0500, arnuld <sunrise>
wrote: >> On Mon, 29 Sep 2008 12:28:59 +0000, James Kuyper wrote: > >> What does that have to do with it? what you pass to feof() and ferror() >> is not the value returned by the I/O function. What you pass it is the >> FILE* associated with the stream that you are using the I/O function on. >> The getchar() function is exactly equivalent to getc(stdin); it's >> provided as a separate function from getc() only for convenience. All >> you need to do is check feof(stdin) and ferror(stdin). > >I can't, that input character is needed by the program, hence I use ch to >store it. If i use feof(stdin) then I will loose the input and will get >only the integer vale returned by feof or ferror. The input character is >needed because we are storing them You seem to think that feof or ferror perform some action against the data in the stream. That is not true. They merely test and report the status of certain indicators associated with the stream. |
|
#218
|
|
|
|
|
jellybean stonerfish <stonerfish> writes:
> On Thu, 18 Sep 2008 22:46:07 +0500, arnuld wrote: > > > You are wrong. Most Indian students say that you need Windows to run a > > computer, without Windows you can not use a computer. I have yet to meet > > a person who uses Linux as his daily use OS. > > > > > > > > Off topic, but what the hell. I, living in Southern California, have yet > to meet anybody who uses linux. Besides myself, and people I have given > computers to. I work in construction, and have been in many offices, and > have seen nothing but window and mac boxes. Eventually, if my children > let me have some free time, I will join a LUG. Linux is alive and well in Pasadena and the San Gabriel Valley. Check SGVLUG - in fact there is a meeting tomorrow night (the second Thursday of each month), and drop-ins are welcome. |
|
|
|
|
| Similar Threads | |
| Best way to input from stdin? I'm writing a program that supports input from stdin. To be able to do that I tend to rely on a simple loop that tests the return of fgets(), such as the following... |
|
| How to accept input from stdin? Hi, I try to make a wrapper around an existing program, which would behave exactly the same as the original one. But my following attempt was failed. Would you pleaes let me... |
|
| Input using stdin How can I give input to a program using STDIN Suppose I want the program to take the value x=10 On some other site i found it as STDIN.read,but its not working. |
|
| getting input from stdin Hi Im new to unix scripting and now Im trying to get user input from stdin and this is what I did echo "enter your name: " read name and it will run with the pointer to... |
|
| Checking available input on stdin I know this has probably come up frequently, but couldn't find a satisfactory reference... I have some code which needs to read from stdin but must not block waiting for... |
|
|
All times are GMT. The time now is 01:30 AM. | Privacy Policy
|