Hello,
I am still trying to become familiar with the programming language. I am working on a project to code a parser function that will go through a given character array and find the ith space character, then output the position of this space. If the value of i is larger than the number of spaces in the character array, it should output -1. I am running into trouble and would appreciate any help.
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Char sentence = "This is a sentence.";
int i = 2;
int pointer;
pointer = findspace(sentence, i);
Serial.print(pointer);
}
int findspace(Char testsentence[], int counti) {
int spacecounter = 0;
int strlength = testsentence.length();
int ithspace;
for (ik = 0; ik <= strlength; ik++) {
if (isSpace(testsentence[ik]))
spacecounter++;
if (spacecounter = counti)
ithspace = ik;
}
if (i > spacecounter)
ithspace = -1;
return ithspace;
}
When I run this I get an error message on the int strlength = testsentence.length(); line that says "request for member 'length' in 'testsentence', which is of non-class type 'char*'". Not sure how to proceed. Any help would be appreciated!