i want to create a program that translates a sentance in english to another language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #16
    Why can't you use the file as you did before?
    What are the errors you were getting?

    Using the text file would be a far better idea...

    Comment

    • jerger
      New Member
      • May 2007
      • 77

      #17
      i guess i am lost. this one compiled so i was like sweet!

      but the other one I hadn't compiled right. so i should try it again.

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #18
        Generally (in programs this small), so long as you can find the first error during compile, the problem is (reasonably) easy to trace.
        When strange errors appear, it is most commonly mismatched parentheses or missing semi-colons.

        Comment

        • jerger
          New Member
          • May 2007
          • 77

          #19
          deman i get these errors with your code

          Code:
           
          37 C:\hmong dictionary.cpp no matching function for call to `strncmp(std::string&, std::string&, <unknown type>)' 
            
          note C:\temp\Dev-Cpp\include\string.h:51 candidates are: int strncmp(const char*, const char*, size_t)

          Comment

          • DeMan
            Top Contributor
            • Nov 2006
            • 1799

            #20
            you can try substituting english.length( ) with english.size()
            (in fact english is not declared in my original example, so you may like to add "string english" below "string line" if you haven't already.

            Seeing as you have got an array version working, you may like to add the filehandling from the first with the array operations of the latter (then you don't need the strncmp), so that you read from a file into an array. Once you have the array, you can use the find method as you are.

            Comment

            • jerger
              New Member
              • May 2007
              • 77

              #21
              i made your changes, similiar issue occurs. do we have to define the function at the bottom of the code? what would i do for that? this is what i got

              errors:
              37 C:\hmong dictionary.cpp no matching function for call to `strncmp(std::s tring&, std::string&, <unknown type>)'

              note C:\temp\Dev-Cpp\include\str ing.h:51 candidates are: int strncmp(const char*, const char*, size_t)

              code:


              #include <iostream>

              #include <fstream>

              #include <string>

              using namespace std;



              int main () {

              string line;
              string english;


              cout << "Type the english words here, then press enter. Make sure to copy the words correctly. If you need to spell check use www.google.com" ;

              cin >> english;

              ifstream myFile ("c:\\eAh.txt") ;

              if (myFile.is_open ())

              {

              while (! myFile.eof() )

              {

              getline (myFile,line);

              // int strncmp(line, english, english.length( ));

              {
              if (strncmp(line, english, english.size))
              cout <<"Match found"<< line;

              }

              }

              myFile.close();

              }



              else cout << "Unable to open file";


              }

              Comment

              • jerger
                New Member
                • May 2007
                • 77

                #22
                btw do you sleep? hahaha you are a great help

                Comment

                • DeMan
                  Top Contributor
                  • Nov 2006
                  • 1799

                  #23
                  This is generally considered bad practice, but you could try adding a cast to see if whether that's the problem:

                  strncmp(line, english, (size_t)(englis h.length()));
                  or
                  strncmp(line, english, (size_t)(englis h.size()));


                  [I'm in Australia so its almost 9 am here.....]

                  Comment

                  • jerger
                    New Member
                    • May 2007
                    • 77

                    #24
                    :(

                    that just causes more problems err. hehe

                    Comment

                    • DeMan
                      Top Contributor
                      • Nov 2006
                      • 1799

                      #25
                      I'll have a think about it.....
                      you can use
                      strcmp(String1, String2)
                      which doesn't need length (the one with length is considered safer because people find it harder to manipulate into overflowing/injecting format strings etc (because you limit the length), for a local app (and certainly for now), it may be worth trying it. )

                      Comment

                      • jerger
                        New Member
                        • May 2007
                        • 77

                        #26
                        12 C:\hmong dictionary.cpp expected constructor, destructor, or type conversion before '(' token

                        12 C:\hmong dictionary.cpp expected `,' or `;' before '(' token


                        if i actually put the ; in after this, it recreates both the new and old error messages! errr it makes no sense

                        Comment

                        • DeMan
                          Top Contributor
                          • Nov 2006
                          • 1799

                          #27
                          you could also use
                          [code=cpp]

                          int pos = line.find(engli sh);
                          if(pos!= string::npos)
                          {
                          //pos is the position of the begining of the word you are searching for in the
                          // string from the dictionary. If you have set up the file to have each line
                          // word, definition
                          // then pos must be 0 to be a valid word (otherwise you may get strange
                          // results - eg looking for "at" would leave pos= 1 in a string beginning "cat")
                          }
                          [/code]

                          Comment

                          • DeMan
                            Top Contributor
                            • Nov 2006
                            • 1799

                            #28
                            This error is at line 12 (which I suspect is where you declare the strings)

                            Comment

                            • jerger
                              New Member
                              • May 2007
                              • 77

                              #29
                              this just makes me more confused haha. it compiles, but just couts nothing and then closes

                              Comment

                              • jerger
                                New Member
                                • May 2007
                                • 77

                                #30
                                weird my .txt file i had

                                a little
                                awhile

                                it would not find awhile, it would just show up blank and do nothing.

                                i then put this in my .txt

                                fa
                                a little
                                awhile

                                and it worked! lol. i wonder why it hates two word, words....

                                also if you put...

                                fart
                                fa
                                a little
                                awhile

                                and search for fa, you get fart as your return

                                Comment

                                Working...