I am getting a "string subscript out of range" message when running this, but do not know what is wrong with my variable "inputchar" (it is used as an index).
I am getting a "string subscript out of range" message when running this,
Where are you getting this error? Your debugger should be able to tell you exactly where it detected the problem and let you view the values of the various variables at the time of the crash.
but do not know what is wrong with my variable "inputchar"
Other that it being a global variable what makes you think there is something wrong with this variable?
The "string subscript out of range" message is an "Assertion Failed dialog box", not an error message that I would get in a list. For this reason, the message does not tell me the line that is causing the problem.
I think that their is something wrong with inputchar because (if I am right) "subscript out of range" means you are indexing an array (or in this case a string), with a bad index.
If targetword is larger than text, you will have the problem you indicated. In that case, the index calculated on line 28 will be greater than the length of text.
I have tried messing with line 28, and am still getting the "Assertion Failed" dialogue box. This makes sense, though. The character '\0' represents the final character in a string.
Can someone please just find the source of my problem?
You'll need to post the smallest possible complete program that illustrates the problem if you want someone to locate the actual problem. But you should run the program with your debugger, your debugger will tell you the exact line where it detects the problem.
You are feeding the arguments to occurrances backwards. And since I would imagine the sentence is larger than the targetword, you're going to have the problem I mentioned earlier.
I use Visual Studio 2017, and do not get any "real" error message, but get the dialog box.
My code counts the amount of times a word is found in a string. I have another function that you can replace occurances with, but it stops at the fist time the targetword is found.
here it is: