:( There is a programming question. This is searching program. there is a string array. In this string array ther is a sentence. I get a word from the user . When the user's word is match with the sentence that is in the string , a message will appear ( found!!) and the number of count else (Not found!!).
My coding:
main()
{
int count ;
char st1[80];
char st[80]={ ncc education examination ncc ncc ncc education};
cout<< "Enter a word to be search";
cin>> st[];
{


}
How can I contiue write this program.Please continue write this program. Help me!

Dani AI

Generated

For : the posted code has a few syntax and logic problems that make it fail before any searching happens — invalid char-array initialization, cin >> st[]; is not valid, '/0' should be '\0', and the loop/strcmp/isspace usage is mixed up. As hinted, manual character-by-character comparison can work, but in C++ it is safer and much simpler to use std::string and the standard tokenization helpers.

A compact, robust approach is: keep the sentence in a std::string, read the search word, split the sentence into tokens with std::istringstream, and compare tokens (optionally case-insensitive). Example implementation:

#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <cctype>

int main() {
    std::string sentence = "ncc education examination ncc ncc ncc education";
    std::string word;
    std::cout << "Enter a word to search: ";
    if(!(std::cin >> word)) return 0;

    auto tolower_str = [](std::string &s){
        std::transform(s.begin(), s.end(), s.begin(),
                       [](unsigned char c){ return std::tolower(c); });
    };
    tolower_str(word);

    std::istringstream iss(sentence);
    std::string token;
    int count = 0;
    while(iss >> token) {
        tolower_str(token);
        if(token == word) ++count;
    }

    if(count) std::cout << "Found!! Count: " << count << '\n';
    else      std::cout << "Not found!!\n';
    return 0;
}

Notes and pitfalls: use std::getline if the sentence comes from user input (so spaces are preserved); tokenization above treats punctuation as part of a token (use regex or strip punctuation for cleaner word matching); prefer std::string over raw char buffers to avoid buffer overflows; use whole-word checks (token compare) rather than substring find unless substrings are intended. This fixes the immediate syntax errors in the original posts and gives a clear, maintainable solution.

Recommended Answers

All 3 Replies

do you have a specific question besides how do I do my assignment? we are not here to do student's homeworks but to help out in specific areas...

you are not usign strings, you are usign char, but more specifically a char array
to do your assignment check to see if the first character of the user char equals the first character of the item you are trying to match, if it is then move onto the next char, if you find even a single item that does not match then it is not equal... there is the psuedocode for the assignment

:( There is a programming question. This is searching program. there is a string array. In this string array ther is a sentence. I get a word from the user . When the user's word is match with the sentence that is in the string , a message will appear ( found!!) and the number of count else (Not found!!).
My coding:

main()
{
    int count ;
    char st1[80];
    char st[80]={ ncc education examination ncc ncc ncc education};
    cout<< "Enter a word to be search";
    cin>> st[];
    {    






    }

How can I contiue write this program.Please continue write this program. Help me!

There is a programming question. This is searching program. there is a string array. In this string array ther is a sentence. I get a word from the user . When the user's word is match with the sentence that is in the string , a message will appear ( found!!) and the number of count else (Not found!!).
My coding:

main()
{
int count ;
char st1[80],st2[80];
char st[80]={ ncc education examination ncc ncc ncc education};
cout<< "Enter a word to be search";
cin>> st[];
int i=0;
{ 

   while(st[i]!='/0')
   {   st3[i]=st1[i];
       st3++;
        while((isspace(st[i])))
         if( stcmp(st1,st3));
       count++;
          {cout<< "found";}
       else {cout<<"Not fjound!!";}
       }
        st1[i]++;
       }
}

<< moderator edit: added [code][/code] tags >>

Please test this program is wrong or true .If in this program have a little wrong please correct it .

There is a programming question. This is searching program. there is a string array. In this string array ther is a sentence. I get a word from the user . When the user's word is match with the sentence that is in the string , a message will appear ( found!!) and the number of count else (Not found!!).
My coding:

main()
{
int count ;
char st1[80],st2[80];
char st[80]={ ncc education examination ncc ncc ncc education};
cout<< "Enter a word to be search";
cin>> st[];
int i=0;
{ 

   while(st[i]!='/0')
   {   st3[i]=st1[i];
       st3++;
        while((isspace(st[i])))
         if( stcmp(st1,st3));
       count++;
          {cout<< "found";}
       else {cout<<"Not fjound!!";}
       }
        st1[i]++;
       }
}

<< moderator edit: added [code][/code] tags >>

Please test this program is wrong or true .If in this program have a little wrong please correct it .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.