• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C


  • Subject: Re: C
  • From: Neil Earnshaw <email@hidden>
  • Date: Fri, 29 Aug 2003 20:32:21 +0100

#include <stdio.h>

int main()
{
int temp[31];
int index, total; // Note that total is never used!
index = 0;

// Clear the array

for ( index = 0 ; index < 31 ; index++ ) {
temp[index] = 0;
}

// Accept values

index = 0;
do {
printf("temp[%d], to quit type 555: ", index);
fflush(stdout); // otherwise you may not see the printed output
scanf("%d", &temp[index]);
// You forgot to increment index, so everything was being put into temp[0]
// So...
index++;
} while (index < 31 && temp[index-1] != 555);

// Note that if you do enter 555 it _will_ go into the array
// Also, note that its very easy to forget to increment your counter
// when using do-while and while loops
// Get in the habit of using for loops; their very structure forcibly
// reminds you to increment the counter

// Exercise: rewrite the above as a for loop

// Show the results

for ( index = 0 ; index < 31 ; index++ ) {
printf("temp[%d] = %d\n", index, temp[index]);
}

return 0;
}

-Neil

On Friday, August 29, 2003, at 07:32 PM, Michael Kozerew wrote:

hi, i`am learning C, and i has faced a problem
int main()
{
int temp[31];
int index, total;
index = 0;
do
{
printf("temp #%d, \
to quit type 555: ", index);
scanf("%d", &temp[index]);
}
while (index < 31 && temps[index-1] != 555);
}
maybe someone say what i do wrong(why the cycle does not stop on 555,
and values are not remembered )?
_______________________________________________
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.


Neil Earnshaw
Consultant Software Engineer
Object Software Engineers Ltd
email@hidden
Tel : 01747 854 852
Mbl : 07870 209 102
_______________________________________________
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.

References: 
 >C (From: Michael Kozerew <email@hidden>)

  • Prev by Date: Re: C
  • Next by Date: Re: C
  • Previous by thread: Re: C
  • Next by thread: Re: C
  • Index(es):
    • Date
    • Thread