CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Clearing arrays

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Dandy
Guest







Clearing arrays
PostPosted: Thu Feb 03, 2005 9:08 am     Reply with quote

Hey guys (and gals)
i'm making an embedded device which, all in all, needs to disect packets for strings within. Problem i'm having is that it stores the the text from a packet within an array.. then... over writes the array with the new packet when it comes in. This works fine until i get a short packet.

The array will fill up with say.."dandy likes work"
then when the next packet sent is "meow"

the array now holds "meowy likes work"

i can think of a loop to clear each value back to zero, but is there any quicker way?
Thanks
Dan
Guest








PostPosted: Thu Feb 03, 2005 9:27 am     Reply with quote

memset() could work for you. But i don't know how it would compare in speed to a loop.
valemike
Guest







PostPosted: Thu Feb 03, 2005 10:10 am     Reply with quote

Shouldn't you put the null character after "meow"? Then when you send the string, send only the chars before the null char.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Feb 03, 2005 12:14 pm     Reply with quote

The standard for strings in C is to terminate them with a null (0x00). Any string processing function stops when it reads a null.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 03, 2005 3:38 pm     Reply with quote

Don't know how you are receiving the data or storing it. But if you are using a pointer and incrementing it after each store, then just assign it a 0 value at that point. Any more data that comes in will overwrite the 0 if no more data comes in then the string is null terminated.
Dandy
Guest







arrays
PostPosted: Sun Feb 06, 2005 8:31 am     Reply with quote

THANK YOU ALL OF YOU!!!
the origional purpose i was using it for, i can't seem to remember what i was trying to achieve.. or indeed grasp how i am to do it... or maybe i think i may have worked around it... fantastic help though, memset() i'll have to give a try.
MOST IMPORTANTLY

i was having some real trouble with using strstr() (search for string within string).

Before when my code was working with one predefined string, the stycpy(variable,”string”) automatically added the \0 at the end. When i changed the code to work with character arrays, i wasn't including the \0 character, therefore all sorts of problems were happening.
so when i changed the char arrays to all include a delimeter, it all worked hunky dorey, and now i can use variable length arrays.
Cheers guys, you saved me days of struggle and made my final year degree project that much better.

Dan
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group