Hey, new here. I have a method called wordCount() which returns an int value for the number of words in a string. I want to make an array that has a wordCount() number of indexes. The compiler doesn't like how I'm setting the size of the array as a variable. Any help is much appreciated!
The compiler doesn't like how I'm setting the size of the array as a variable
But you decided not to share what you shared with the compiler.
Good luck.
Thought I explained it well enough, sorry about that. adminInput is a String, wordCount returns an int value, myInput is the array Im trying to setup:
String myInput[wordCount(adminInput)];
(deleted)
Hey, new here
"Date Registered: 20-08-2012, 01:51:04" :o
Thanks for the help guys.
You're very welcome.
Just make the array big enough for the largest message.
Plus ... It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.
...R
Serial Input Basics
Thanks Robin2, but the message changes in size throughout the program. Im using a variable to keep track of the size of the message and change the size of the array accordingly.
The number of words in a string (or even a String) can't exceed half the number of characters in the string (or String).
Try not to mix strings and Strings.
Thanks AWOL, interesting solution. But with a large message I'd be setting up a ridiculously large array.
This is getting to be a ridiculously long thread with precious little detail
You've got five minutes between posts; I cannot imagine why you're not using them more productively
And if you don't allow for the large array size and the big message comes, what happens when you cannot allocate that much memory?
But if you get that ridiculously long message, you still have to. Aka, solution is NOT to send that or at least to process a part while receiving
My question was rhetorical. I suspect the answer is going to be, "Hmm, I hadn't thought about that."
roboticfan101:
Thanks Robin2, but the message changes in size throughout the program.
...which us precisely the exact type of usage pattern which causes memory fragmentation with String and your program suddenly does something strange "for no reason whatsoever." Usually when you can't physically get to it and it turned out to be really important to keep that one Arduino running.
roboticfan101:
Thought I explained it well enough, sorry about that. adminInput is a String, wordCount returns an int value, myInput is the array Im trying to setup:String myInput[wordCount(adminInput)];
You don't know what the problem is. Don't assume that you know what information is needed to solve it. That single isolated line helps nothing.
I have a suspicion about what the problem is, but I can't confirm it without knowing where in your program the variable declaration is and what message you're getting from the compiler. I'm not going to go out of my way testing random hypotheticals just for the chance to learn later that that's not actually your problem.
Why don't you post a (representative example of your code) and of your message?