Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 118:5b2bc88d441d, committed 2021-10-15
- Comitter:
- CSTritt
- Date:
- Fri Oct 15 18:09:56 2021 +0000
- Parent:
- 117:b40379408898
- Commit message:
- Cleaned up formatting and comments.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Oct 14 15:48:50 2021 +0000 +++ b/main.cpp Fri Oct 15 18:09:56 2021 +0000 @@ -9,7 +9,7 @@ sequences. Switched from return to sleep loop. Ported to mbed by C. S. Tritt - Last revised: 10/14/21 (v. 1.2) + Last revised: 10/15/21 (v. 1.3) */ #include "mbed.h" @@ -27,6 +27,8 @@ // main function - Console mode C/C++ execution starts here. int main(void) { float samples[MAX_COUNT] = {0.0}; // Create & initialize sample array. + // Note un-indexed arrays pass as pointers so content of samples can and is + // changed in this call. int sampleCount = getData(samples, MAX_COUNT); // Get values. float theAverage = myAverage(samples, sampleCount); // Find average. userOut(theAverage); // Display results. @@ -55,12 +57,12 @@ pc.printf("Number of values to average (Maximum %d)? ", max_size); pc.scanf("%d", &nValues); // Caution: scanf is fragile. pc.printf("%d was read.\n", nValues); // added by cst. - if(nValues > max_size) { + if (nValues > max_size) { pc.printf("Maximum count exceeded. %d items will be read.", max_size); nValues = max_size; } printf("Enter values:\n"); - for( int i = 0 ; i < nValues ; ++i) { + for(int i = 0 ; i < nValues ; ++i) { pc.scanf("%f", &data[i]); pc.printf("%f was read.\n", data[i]); // added by cst. }