Without your guys' help I'd be stuck. Thanks.
Now there are issues with how my code is written. It's really weird. I decided to use a 2 dimensional array becuase I have never used them before and I don't understand how pointers work.
Here is the current code with notes where stuff doesn't work:
Code:
/*Not working*/
/*Program to take sentence user writes and divide into seperate words and
store each word in an array
Skipped commenting first section because it is pretty obvious what's
going on*/
#include <iostream>
#include <string.h>
using namespace std;
int words();
char sentence[150] = {' '};
int main()
{
cout << "Enter any words:" << endl;
cin.getline(sentence, 150);
words();
}
int words()
{
int wordCount = 0;
char wordGather[15] = {' '};
char word[10][15] = {'k'};
int y = 0;
int sentenceLength = strlen(sentence);
for(int c = 0; c < sentenceLength; c++) //Start checking for spaces.
{
if(sentence[c] == ' ') //If a space occurs,
{ //
for(int x = c; x > 0; x--) //Count down from point in array
{ //sentence where a space occured.
//
y = y + 1; //
if(sentence[x] == ' ' || '/0') //If a space occurs or
{ //the end, stop checking.
cout << "Working here" << endl;
break; //the '|| "/0"' part doesn't work
} //will output cout stuff x-1 times
//when x=number of words typed
/*stops working here (because of the break?)*/ //
else //If no spaces occur, assign
{ //identified word's chars to array
//'wordGather'.
wordGather[y] = sentence[x];
word[wordCount][y] = wordGather[y]; //Assign word
} //collected in 'wordGather' to
//space <wordCount> in array
//'words'.
}
wordCount = wordCount + 1;
}
}
//below is to stop the program from closing; my compiler doesn't add
//the press enter to close feature to programs
cout << word[1][2];
//If I don't initialize the array 'word' to all spaces, then I get
//some wacky characters that I have never seen before.
int stop;
cin >> stop;
return 0;
}