I need help

I’m a beginner and I have a homework assignment due in the morning and two of the question are related and I can’t get the first part working. Basically, the program is supposed to find whatever space number you want in a sentence. If the sentence is “This is a sentence” and you say the index is 2, the function findspace is supposed to output 8 because the second space is the 8th character. This is my code:

void setup() {

Serial.begin(9600);

int pointer;
int findspace;

const char sentance=“This is a sentence”;
const int index=1;
pointer=findspace(sentence,index);

Serial.print(pointer);
}

void loop() {

int findspace(char phrase,int space); {

int lsent=strlen(phrase);
int spacenum=0;

for (int i=0; i<=lsent; i++) {
if (phrase*==’ ') {*

  • spacenum=spacenum+1;*

  • if (spacenum==space) {*

  • return i;*

  • }*

  • }*

  • else {*

  • spacenum=spacenum;*

  • if (i==lsent && spacenum<space) {*

  • return -1;*

  • }*

  • }*

  • }*
    }

You have a function defined inside another function. That won't work. Move the definition of findspace outside of loop.

If you really are in a hurry, then read the How to Use This Forum post right now and learn to post code properly so it won't turn into italics so you don't waste a bunch of time being told to go back and post it right.

Ok, thank you.

Check your variable names for typos. I can see a 'sentance' and 'sentence' that probably need to match.

Why is your code in italics?