hi,
Iam using a Dev-c++4 compiler and i am stuck on one line of a program to show the word of a sentence e.g. the last word is Ireland should show up on screen when program is run
ANSI C++ forbids comparison between pointer and integer
This message shows up on my compiler i have tryed eveything to get rid of it.
It applys to this line of code : for(i =(intlength -1); Array != ' '; i--)
,
What are you doing with Array[intlength]? Your sentence is stored in strSentence. You shouldn't mix up strings and char-arrays.
Either you have a char array containing the string, and you use the for-loop to find the position of the last whitespace. for(i=intlength-1;Array[i]!=' ';i--){}
(Do not forget to add the braces, otherwise the command LastWord = Array will be executed in every loop)
Then you can have LastWord (with should be a pointer to char, not an array) point to the position i in the Array. LastWord = Array[i]
And then you can cout LastWord.
Or you are using strings. With the sentence stored in strSentence you can find the location of the last whitespace by int position = strSentence.find_last_of(' ')
And you can extract the last string with string lastword = strSentence.substr(position)