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

problem with string

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



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

problem with string
PostPosted: Sat Aug 09, 2008 5:12 am     Reply with quote

Hi ALL
How can I empty the string? for example I define J[40] and with serial communication (RS232) get 40 characters. I want to keep on this loop and I need to make J empty. How can I do that?
ROBOTICAR



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

PostPosted: Sat Aug 09, 2008 10:55 am     Reply with quote

and another question.
How can I change 3256.212 into 3256212 ??
Guest








PostPosted: Sat Aug 09, 2008 7:44 pm     Reply with quote

Code:

memset(J, 0, 40);


you will need to include string.h to use memset.

You could also make a for loop

Code:

for(x=0;x<40;x++)
{
  J[x] = 0;
}



As for your second question, you need to make sure that the variable storing the second number will be of a large enough type. An unsigned 32 bit integer will do the trick. Then just multiply by 100.
Guest








PostPosted: Sat Aug 09, 2008 7:45 pm     Reply with quote

Anonymous wrote:
Then just multiply by 100.


Sorry, I meant 1000
SherpaDoug



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

View user's profile Send private message

Re: problem with string
PostPosted: Sun Aug 10, 2008 5:03 am     Reply with quote

ROBOTICAR wrote:
Hi ALL
How can I empty the string? for example I define J[40] and with serial communication (RS232) get 40 characters. I want to keep on this loop and I need to make J empty. How can I do that?


First you must define "empty". In C strings are usually terminated with a null (0x00). So if you make the first byte of the string null the string will be empty. If this is a serial buffer with head and tail pointers you can make it empty by setting the two pointers to the same address.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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