The programs purpose is that you let the user write a sentence and then the user can search the sentence for a word and if it finds one in the sentence the console will then tell the user its correct and so on.
But I have done the same program with string, but I wish to create it with char arrays this time but I fail miserably and I can't figure it out. the problem is that The user cant find the word in the sentence. Well the code is here:::
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- int main(int argc, char** argv)
- {
- int get = 0;
- char sentence[56];
- char word[10];
- std::cout << "Please write a sentance; \n";
- std::cin.getline(sentence, 56);
- std::cout <<"your sentance is: \n" << sentence << std::endl;
- std::cout <<"Now search for a word in your sentance:"<< std::endl;
- std::cin >> word;
- while ( get < 56)
- {
- if (sentence[get] == word[1])
- {
- get++;
- if (sentence[get] == word[1])
- {
- std::cout << "Thats a word in your sentence\n\n";
- break;
- }
- else
- {
- get++;
- }
- }
- else
- {
- std::cout << "Sorry, thats not a word in your sentence.\n\n";
- get++;
- break;
- }
- }
- return 0;
- }
I am prolly just really confused...