Re: Beginning programmer... I need some help.



bmlclemson08 wrote:

OK the new code i have so far is:
#include <stdio.h>

int main ()
{
int current_in, largest_so_far, counter;

printf ("Enter your numbers:\n");

scanf ("%d", &largest_so_far);

for (counter = 0; ; counter = counter + 1)
{
scanf ("%d", &current_in);

if (largest_so_far < current_in)
largest_so_far = current_in;
if ((current_in = getchar()) != EOF)
{
break;
}

Here, you break out of `for` loop only if getchar() does /not/ return
EOF, probably not what you wanted. Did you mean to type `==`?

Anyway, read my other post, and try to implement my suggestion. I don't
think you're on the right path here (e.g. your current solution does
not cater for /no/ integers at all).

Cheers

Vladimir

PS
Also keep in mind that your getchar() call "eats" the non-EOF characters
(to pedants: I know EOF is a condition, not a character). You may be
better of using getc() and if it does not return EOF do an ungetc().

--
Very few profundities can be expressed in less than 80 characters.

.



Relevant Pages

  • Re: malloc + 4??
    ... >the screen or to a file, there aren addition 4 characters. ... This loop tries to count the size of the file by calling getc ... until getcreturns EOF. ... yet also return the special marker value EOF. ...
    (comp.lang.c)
  • Re: K&R 1.5.1 exercise
    ... Your while loop will eventually cause integer overflow, ... > It would have been even better if you used a loop, with getchar!= EOF ... > getchar() call will return the code of the first character you have typed ...
    (comp.lang.c)
  • Re: detab utility challenge.
    ... I know he is not suggesting anyone write such a silly loop. ... Once the character returned is EOF, ... possible input characters", and the gods must be crazy, since they are ...
    (comp.lang.c)
  • Re: some "newbie" questions
    ... Buck Rogers wrote:> ... c = (getchar()!= EOF) ... the program reads characters from the standard input and ...
    (comp.lang.c)
  • Re: C newbie problem
    ... while(c = getchar()!= EOF){ ... In your loop test, you say you want to continue as long as the getchar ...
    (comp.lang.c)