Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Windows increments variable |
| Date | 2011-11-02 20:49 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <j8sadm$jc8$1@reader1.panix.com> (permalink) |
| References | <2606bf70-4a4f-438d-a86f-dae68a807a9b@p16g2000yqd.googlegroups.com> |
In <2606bf70-4a4f-438d-a86f-dae68a807a9b@p16g2000yqd.googlegroups.com> BSDBlack <bsdblack@googlemail.com> writes:
> #include <stdio.h>
> int main(void) {
> int i, f[2];
> for(i = 0; i<= 2; i++) {
> scanf("%d", &f[i]);
> fflush(stdin);
> }
As others have said, f is a two-element array. C arrays start at zero,
so the only valid elements in f are f[0] and f[1]. If you want to have
three elements in f, declare f as f[3].
> if(f[0] == f[1] || f[1] == f[2] || f[0] == f[1] || (f[1] == f[2]
> &&
> f[1] == f[0])) printf("Same Numbers;\n");
> else if(f[1] < f[0] && f[2] < f[0])
> printf("%d\n", f[0]);
> else if(f[0] < f[1] && f[2] < f[1])
> printf("%d\n", f[1]);
> else if(f[0] < f[2] && f[1] < f[2])
> printf("%d\n", f[2]);
> return 0;
> }
> when I run this program under Windows and input 4, 5, 6 it returns 7;
> when I run this program under FreeBSD and input 4, 5, 6 it returns 6;
Unless things have gone horribly wrong, this program should only return
zero.
Did you mean that the program prints (instead of returns) 7 or 6?
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Windows increments variable BSDBlack <bsdblack@googlemail.com> - 2011-11-02 13:03 -0700
Re: Windows increments variable "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-11-02 16:38 -0400
Re: Windows increments variable rudolf <r.thered@gmail.com> - 2011-11-02 13:42 -0700
Re: Windows increments variable John Gordon <gordon@panix.com> - 2011-11-02 20:49 +0000
Re: Windows increments variable BSDBlack <bsdblack@googlemail.com> - 2011-11-02 14:11 -0700
Re: Windows increments variable BSDBlack <bsdblack@googlemail.com> - 2011-11-02 14:14 -0700
Re: Windows increments variable Martin Ambuhl <mambuhl@earthlink.net> - 2011-11-03 14:13 -0400
csiph-web