Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. String In C++

String In C++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++algorithmsregexlearning
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hack Baba
    wrote on last edited by
    #1

    Plz Help Me, I am trying to make a school project which is a search engine that takes input from the user and searches the entered word or sentence within the files available. There's no compile error in the program but the program is not searching correctly the file which has the data. If the entered string matches any sentence or string in the file stored then it should display the result. But the problem is that the strcmp or stricmp or any function which searches for a match is not working. I am using it with if & else statement for now... If the string is in the file then it should show found else not found but it only works if there is only one word in the file. If the file which is to be searched has lots of data off course in the text format it always shows not found but if it has only one word then it says found. Plz help Me If You Can.

    void search()
    {

    char str2[100];

    char str[100];

    cout<<"write some text to search:";

    gets(str);

    ifstream i;

    i.open("stud.txt");

    while(!i.eof())
    {
    i>>str;
    }

    if(stricmp(str,str2)==0)
    
     cout<<"found !";
    
    else
    
     cout<<"not found !";
    

    getch();

    }

    CPalliniC J 2 Replies Last reply
    0
    • H Hack Baba

      Plz Help Me, I am trying to make a school project which is a search engine that takes input from the user and searches the entered word or sentence within the files available. There's no compile error in the program but the program is not searching correctly the file which has the data. If the entered string matches any sentence or string in the file stored then it should display the result. But the problem is that the strcmp or stricmp or any function which searches for a match is not working. I am using it with if & else statement for now... If the string is in the file then it should show found else not found but it only works if there is only one word in the file. If the file which is to be searched has lots of data off course in the text format it always shows not found but if it has only one word then it says found. Plz help Me If You Can.

      void search()
      {

      char str2[100];

      char str[100];

      cout<<"write some text to search:";

      gets(str);

      ifstream i;

      i.open("stud.txt");

      while(!i.eof())
      {
      i>>str;
      }

      if(stricmp(str,str2)==0)
      
       cout<<"found !";
      
      else
      
       cout<<"not found !";
      

      getch();

      }

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      How could we possibly help without seeing your code?

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • H Hack Baba

        Plz Help Me, I am trying to make a school project which is a search engine that takes input from the user and searches the entered word or sentence within the files available. There's no compile error in the program but the program is not searching correctly the file which has the data. If the entered string matches any sentence or string in the file stored then it should display the result. But the problem is that the strcmp or stricmp or any function which searches for a match is not working. I am using it with if & else statement for now... If the string is in the file then it should show found else not found but it only works if there is only one word in the file. If the file which is to be searched has lots of data off course in the text format it always shows not found but if it has only one word then it says found. Plz help Me If You Can.

        void search()
        {

        char str2[100];

        char str[100];

        cout<<"write some text to search:";

        gets(str);

        ifstream i;

        i.open("stud.txt");

        while(!i.eof())
        {
        i>>str;
        }

        if(stricmp(str,str2)==0)
        
         cout<<"found !";
        
        else
        
         cout<<"not found !";
        

        getch();

        }

        J Offline
        J Offline
        Joe Woodbury
        wrote on last edited by
        #3

        You are reading the file and keyboard input into the same string.

        H 1 Reply Last reply
        0
        • J Joe Woodbury

          You are reading the file and keyboard input into the same string.

          H Offline
          H Offline
          Hack Baba
          wrote on last edited by
          #4

          Sorry for the incorrect edit. The string was str which was getting the input and the string which reads the file is different as you said in the code. I searched for the last word in the file and then it says found !. So that means it is working correctly but it's only searching for the last word in the file. What to do ?

          J 1 Reply Last reply
          0
          • H Hack Baba

            Sorry for the incorrect edit. The string was str which was getting the input and the string which reads the file is different as you said in the code. I searched for the last word in the file and then it says found !. So that means it is working correctly but it's only searching for the last word in the file. What to do ?

            J Offline
            J Offline
            jeron1
            wrote on last edited by
            #5

            Put the test for equivalency inside the while loop. Currently the while loop reads all strings, when it exits the last string is in the variable, which you then test for.

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            H 2 Replies Last reply
            0
            • J jeron1

              Put the test for equivalency inside the while loop. Currently the while loop reads all strings, when it exits the last string is in the variable, which you then test for.

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

              H Offline
              H Offline
              Hack Baba
              wrote on last edited by
              #6

              It's still searching for the last word Even after putting it into the while loop. Plz Help

              1 Reply Last reply
              0
              • J jeron1

                Put the test for equivalency inside the while loop. Currently the while loop reads all strings, when it exits the last string is in the variable, which you then test for.

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                H Offline
                H Offline
                Hack Baba
                wrote on last edited by
                #7

                Bro it's still the same. It's only searching for the last word of the file. Plz tell me what to do. I don't know what's happening

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups