I am working on a small assignment and I got it to compile but it is not returning what it is suppose to. I would like to read a line from the keyboard and assign a "const char" to it but I don't know what I am doing wrong. Here is the code I have:
You cannot read a full sentence into a variable of type char. You need an array of chars. I would imagine this is something you are told in the first couple of sessions.
Alternatively, since you are using C++, you could use std::string, a String class that has all sorts of useful methods, including one called find() that does exactly what you want (and what the name implies).
In any case, to correct your code you must read sentences using std::string or char arrays (not single chars). Also don't use the extraction operator (>>) and instead use std::getline().
If you intend to seach for a single character, then that is good, but if not, the 'search' variable also needs to be an array of chars.
Second, I told you to use std::getline(), not cin.getline(). The former is a global function while the latter is a member function of the cin variable. The one I speak of is described here: http://www.cplusplus.com/reference/string/getline/ . However, I just saw in this document that this global function only works with std::string objects, so alas, it was wrong of me telling you to use this function if you are required to use char arrays. My bad. Continue using cin.getline(), but use the overload that takes 3 parameters; the third argument should be '\n' so it stops reading when the user hits the ENTER key.
Finally, since firstString is now an array of chars, line 22 in your original code listing should just read constchar *string1 = firstString;. The & operator is no longer required.