![]() |
| | #1 |
| Embedded in C... Join Date: Sep 2008 Location: Basingstoke, Hampshire
Posts: 65
| I have some arrays in my code which will contain different messages of varying lengths, so I have sized my arrays to take the longest ones (plus 1 or two elements on the end), but how do I ensure that if the message is shorter than maximum, there is not junk in the unused elements which would be sent out my serial port? Thanks Dave |
| droseman is offline | |
| | #2 |
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| before filling the value in your array just Code: memset(array, 0, sizeof(size) * MAX_NUMBER) Code: array[MAX_NUMBER] = {0}
|
| RockyMarrone is offline | |
| | #3 |
| Registered User Join Date: Apr 2006 Location: United States
Posts: 3,202
| The third argument to memset is computed like (sizeof(array[0]) * MAX_NUMBER), because the function expects a number of bytes.
__________________ Os iusti meditabitur sapientiam Et lingua eius loquetur indicium "There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii) http://www.myspace.com/whiteflags99 |
| whiteflags is offline | |
| | #4 |
| Embedded in C... Join Date: Sep 2008 Location: Basingstoke, Hampshire
Posts: 65
| Thanks for that info Rocky, that sounds like just what I need. Just to clarify, I invoke this function when I am declaring my arrays? Also, can I insert this code into a struct member declaration, or would I have to declare my arrays separately first? --dave Last edited by droseman; 11-05-2009 at 06:14 AM. Reason: extra info |
| droseman is offline | |
| | #5 |
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| You are most welcome Enjoy C/C++ programming |
| RockyMarrone is offline | |
![]() |
| Tags |
| array |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| coping elements not in array | lord | C++ Programming | 2 | 08-04-2008 07:53 PM |
| way to check 3 elements of array and set 4th | Syneris | C++ Programming | 3 | 01-09-2006 11:30 AM |
| Class Template Trouble | pliang | C++ Programming | 4 | 04-21-2005 04:15 AM |
| Struct *** initialization | Saravanan | C Programming | 20 | 10-09-2003 12:04 PM |
| A simple question about selecting elements in an array | Unregistered | C++ Programming | 1 | 08-30-2001 10:37 PM |