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 contents of an array

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







Clearing contents of an array
PostPosted: Wed Aug 11, 2004 4:14 am     Reply with quote

What is the easiest way of clearing an array used to buffer characters received from RS232. When I fill array with characters I search for a substring then if it is present I want to set array to contain nothing.
Mark



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

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

PostPosted: Wed Aug 11, 2004 5:58 am     Reply with quote

memset() would do that for you.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Aug 11, 2004 11:55 am     Reply with quote

Code:


void clear_array(int Buffer_NAME, int Buffer_SIZE)
{
int n;
        for(n = 0; n <= Buffer_SIZE; n++)
            {
              Buffer_NAME[n] = 0;
            }
}



Best wishes,

Humberto
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Ring Buffer
PostPosted: Wed Aug 11, 2004 1:26 pm     Reply with quote

Why don,t you use a ring buffer?
Then you don't have to clear it just get the data out of the buffer.
I use them on all of my serial PIC projects.
Look at CCS examples EX_SISR.C.

Tom
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Aug 11, 2004 4:46 pm     Reply with quote

herby handcock asked

Quote:

I want to set array to contain nothing.


Ooops, pls change
Code:

void clear_array(int Buffer_NAME, int Buffer_SIZE)


To:
Code:

void clear_array(int *Buffer_NAME, int Buffer_SIZE)


Humberto Embarassed
.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 12, 2004 8:38 am     Reply with quote

Tom-H-PIC: could you post your ring buffer code into the code library? I have used them in the past,... but I want to find out if I'm doing it in the most efficient way. I'll post mine also.
tjr
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 2:48 pm     Reply with quote

My perference is for linear buffers using an index. When moving data that has a predefined pattern the data can be accessed in the buffer directly rather than indirectly. That makes the code smaller and faster. On the other hand if you are sending or recieving data in a continous stream ring buffers are a better choice. Either way you go you only have to clear the index values not the actual buffer.
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