String Overflow

This really isn't an Arduino question, but there are some really good programers here so thought I would ask,

This code snipit produces a Temp$ over flow

       string Temp$[150]; 	

	do
		{
		iNextChr = GetC(CopyBuf$);
		if(iNextChr <> 0x2C && iNextChr <> 0x2E && iNextChr <> 0x3B) //Filter out the . , and ;
			{
			Temp$ = Temp$ + Chr(iNextChr);
			//Print("%s",Temp$);
			}
		else if(iNextChr = 0x2C || iNextChr = 0x3B)
			{
			iData[iD] = AtoI(Temp$);
			iD = iD + 1;
			Temp$ = "";
			}
		}
	until (iNextChr = 0x3B);

        Temp$ = "";

But changing it to this does not produce a Temp$ overflow and I'm not sure why. I might be misunderstanding how the Do Until loop works.

	string Temp$[150]; 

        while(Len(CopyBuf$) > 0)
		{
		iNextChr = GetC(CopyBuf$);

		if(iNextChr <> 0x2C && iNextChr <> 0x2E && iNextChr <> 0x3B) //Filter out the . , and ;
			{
			Temp$ = Temp$ + Chr(iNextChr);
			//Print("%s",Temp$);
			}
		else if(iNextChr = 0x2C || iNextChr = 0x3B)
			{
			iData[iD] = AtoI(Temp$);
			iD = iD + 1;
			Temp$ = "";
			}
		}
		
	Temp$ = "";

Thanks

Its not C!, some flavour of Basic?

PaulS:

	until (iNextChr = 0x3B);

What purpose is served by assigning a value to iNextChr in this statement? It looks like an equality test would be more appropriate.

Sorry, should have mentioned that this is Crestron Simpl+ programing (Their own version of C) so unlike most where it would normally be == it is only =, so it is in fact an equality test. Using == doesn't compile.

Your termination conditions are different.

The second implementation would process each received character and then stop.

The first implementation would continue reading characters until it finds a 0x3B. If there is no 0x3B in the input stream, and the GetC() function doesn't return 0x3B when there is no more input, then the first implementation will loop forever appending whatever GetC() returns to the string.

PeterH:
Your termination conditions are different.

The second implementation would process each received character and then stop.

The first implementation would continue reading characters until it finds a 0x3B. If there is no 0x3B in the input stream, and the GetC() function doesn't return 0x3B when there is no more input, then the first implementation will loop forever appending whatever GetC() returns to the string.

I kind of thought that myself but the 0x3B is the terminating character for each incoming string, so it should stop at the end. Not to mention that after each comma, the Temp$ should be = ""

More info,

Example of incoming string, (random numbers)

100,34.2,50,65.0,600,0.0,0,40.0,200,34.0,24,50.0,100,35.0,20,40.0,0,0,0,0,25,95;

If I un-comment the print statement to see what Temp$ is I get

10034250650600000400200340245001003502040000002595

on the very first loop and each loop after

Furthermore the information stored in iData[] is correct
iData[0] = 100
iData[1] = 342
iData[2] = 50
iData[3] = 650
etc...

It's working now using the while loop but I am just trying to understand why it isn't working in the do-until loop.
:astonished:

Jassper:
Sorry, should have mentioned that this is Crestron Simpl+ programing

Yes you should definitely have mentioned that. There probably aren't that many Crestron Simpl+ experts on an Arduino/C++ forum.

Isn't there a Crestron Simpl+ forum? This seems totally out of place to me.

Next you'll want help fixing your car.

Yes and no. They think their product is gold so you don't get a straight answers or they expect to get
paid for every bit of info.

Like I said, there are a lot of
good programmers here.
But i see there a few dick's as well.

Jassper:
Like I said, there are a lot of good programmers here. But i see there a few dick's as well.

From one sarcastic remark you conclude that Nick is a bad programmer and a "few dick's"?

I can't tell if that is or is not an insult. It could be. But you incorrectly tried to make "dick" plural when referring to a single person. As written it is statement of what is before your eyes rather than an insult. From his published work, Nick is clearly a decent programmer which directly contradicts your implied mutual exclusion. Your statement makes no sense. You should rewrite it.

Maybe your post was meant to be sarcastic. Is that the case? Was your post an attempt at sarcasm?

I didn't say he was a bad programmer :wink:

If you have nothing to offer to the problem, then just don't replay. He didn't need to belittle, and your post is no better by trying to show your superiority by correcting my grammar and insinuations. Nicks reply was uncalled for just as mine was unfounded. Nick concluded from one post that I'm an Idiot so yes, I concluded from one sarcastic remark that Nick is a dick - seems fair.

The programing is C++ based, the basics are the same. My hope was that someone would have a "possible" reason. I wasn't asking someone to re-write the code in proper syntax - obviously that's not going to happen. PeterH and PaulS at least both offered something constructive and I think PeterH has come close. It at least confirmed that I was on the write track.

That's why I come here, because I get helpful information - regardless.

Now, I have this funny noise in my car....

I never said you are an idiot. I doubt if you are. :slight_smile:

I looked at your code for a while, trying to be helpful, but got stuck on this line:

	until (iNextChr = 0x3B);

In C++ that would be almost certainly wrong, as that is assigning, not comparing. However clearly the code wasn't C (or C++) and you hadn't specified what it is. Although I know quite a few languages that didn't match any I was familiar with. PHP it looked a bit like, however the AtoI was the wrong case for PHP. You see, I tried to do a bit of research for you.

Hence my frustration at being asked to help with so little effort being put into specifying the language. You said it "isn't an Arduino question". It would have been helpful to say "this is a Crestron Simpl+ question".

You go on to say:

The programing is C++ based, the basics are the same.

and also:

this is Crestron Simpl+ programing (Their own version of C) so unlike most where it would normally be == it is only =, so it is in fact an equality test. Using == doesn't compile.

So it's C++ based, but not.

Jassper:
I didn't say he was a bad programmer :wink:
...
Nick concluded from one post that I'm an Idiot

... And he didn't say you were an idiot.