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
Posted: Sat Aug 09, 2008 10:55 am
and another question.
How can I change 3256.212 into 3256212 ??
Guest
Posted: Sat Aug 09, 2008 7:44 pm
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
Posted: Sat Aug 09, 2008 7:45 pm
Anonymous wrote:
Then just multiply by 100.
Sorry, I meant 1000
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Re: problem with string
Posted: Sun Aug 10, 2008 5:03 am
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.
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