Re: C
Re: C
- Subject: Re: C
- From: David Thorp <email@hidden>
- Date: Sat, 30 Aug 2003 05:47:12 +1000
Hi there...
I'm no expert, but I've been very grateful for others answering my C
questions, so maybe I can offer something back here: this is at least
one question I can answer, I think... :-)
Not sure what you're trying to do, but when I put your code into my
terminal or Project Builder and compile, I get a warning:
line 04: total isn't used. -- not sure why you've included that -
only a warning though.
line 11: variable "temps" isn't declared. -- i expect that's a typo
and it should be "temp"
So if I fix those I get this:
01: int main()
02: {
03: int temp[31];
04: int index;
05: index = 0;
06: do
07: {
08: printf("temp #%d, to quit type 555: ", index);
09: scanf("%d", &temp[index]);
10: }
11: while (index < 31 && temp[index-1] != 555);
12: }
This compiles ok, but there's still a couple of problems:
1. Why it doesn't stop at 555: I can't actually find this in any of my
documentation to confirm for certain, but I do believe that the && has
either the same or higher precedence than !=. Please somebody else
correct me if I'm wrong here. Therefore you need to put parentheses in
the conditions for your while statement:
11: while ((index < 31) && (temp[index-1] != 555));
to ensure that the != and the < are evaluated before the &&.
I never bother to remember precedence rules. I just make sure I put
parentheses in anyway (like the above for example) to ensure the right
result, regardless of precedence.
2. Why the values aren't getting remembered. Not sure what you mean by
that, but I notice that at no point is index changed. Not sure what
you're trying to achieve but I assume you want to be incrementing index
somewhere in the loop. I'd be putting index++ after line 09 before the
closing "}" ending the loop.
I'm not sure from your code where you use or display the integers in
the array, but at least you see index incrementing in your printf
statement as you run the program after the above changes.
Hope that helps...
Cheers!
David.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- Follow-Ups:
- Re: C
- From: Clark Cox <email@hidden>
- Re: C
- From: David Thorp <email@hidden>
References: | |
| >C (From: Michael Kozerew <email@hidden>) |