Thread: Forum Auto-Responder

  1. #16
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    there shouldn't be a { between the function name and the list of function arguments. Therefore this:

    void getboard {(qtype item);

    should be this:

    void getboard (qtype item)
    {

    or this:

    void getboard (qtype item) {

    and likewise in all of the functions.

    There should not be a semicolon after the closing brace } of functions.

    strcpy() has two arguments, the destination char array comes first, then a comma, then the source char array. None of your calls to strcpy() follow that format. The source string presumably will come from the file you are reading, but your code never actually reads anything from file, that is there are no calls to >> or get() or getline() or whatever. Given the string is a title of a post or a question raised, there will probably be spaces embedded in the string so you will probably want to use getline() to read the file data in. Given that there will probably be many questions stored in the FAQ you will probably want to store the input in a container of some sort to search, although you could do a strcmp() to compare each string as it is read in with the string from the users post and if there isn't a "match" go to the next string in the file. All of this however, still doesn't settle how you are going to accomplish the matching process given the wide latitude/variability in phrasing questions. The matching process is somehting that probably is in the realm of artificial intelligence, and since I have enough trouble with my own, that topic is far beyond my capability.

  2. #17
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Originally posted by Denethor2000
    easier and more practical way :
    Code:
    #include <iostream.h>
    
    int main()
    {
            cout<<"Hello World";
    }
    you trying too hard
    Forgot return 0;

  3. #18
    Registered User
    Join Date
    Mar 2002
    Posts
    10

    Defined Arrays

    Both of you forgot that I defined my varables as arrays, and then used them as static varables.

    Salvanius, you are WAY ahead of the game here. I agree, AI would be useful in finding the correct results, but I need something that works, first, and that is perfect, eventually.

    Elad, you are being very helpful in your response, but I learn by example, so some of your response, while very relevant, is greek to me. Here is what I could manage:

    PHP Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>

    struct qtype {
       
    char board [80];
       
    char title [80];
       
    char body  [80];
    }

    void getboard (qtype item);
      { 
    ifstream sourcefile ("board.txt");
        
       if (
    sourcefile.fail())
          
    cerr << "Error opening board.txt...";
       else
          (while ! 
    sourcefile.eof());
             
    strcpy (item.board);
             
                 
       
    sourcefile.close();
       return;
    }

    void gettitle (qtype item);
      { 
    ifstream sourcefile ("title.txt");
        
       if (
    sourcefile.fail())
          
    cerr << "Error opening title.txt...";
       else
          (while ! 
    sourcefile.eof());
             
    strcpy (item.title);
          
                 
       
    sourcefile.close();
       return;
    }

    void getbody (qtype item);
     {  
    ifstream sourcefile ("body.txt");
        
       if (
    sourcefile.fail())
          
    cerr << "Error opening body.txt...";
       else
          (while ! 
    sourcefile.eof());
             
    strcpy (item.body);
          
                 
       
    sourcefile.close();
       return;
    }
     
    void output {
       
    cout << board << endl;
       
    cout << title << endl;   
       
    cout << body  << endl;
          
    }

    return 
    0

    If you can repair this one, I will understand:
    PHP Code:
    void getboard (qtype item);
      { 
    ifstream sourcefile ("board.txt");
        
       if (
    sourcefile.fail())
          
    cerr << "Error opening board.txt...";
       else
          (while ! 
    sourcefile.eof());
             
    strcpy (item.board);
             
                 
       
    sourcefile.close();
       return;
    }
    return 
    0
    Then I need to add the varable to make the three arrays, then there must be a way to load these three in one step, instead of three, as I have it now.

    Please rember what Im trying to do in this step
    1 load the three string values

    the next step is
    2 post them to what is loaded into "board", a form

    then add
    1.5 check to see if "title" already exists"

    then add
    3 post multiple boards

    then add
    4 set for other titles to match the same response

  4. #19
    Registered User
    Join Date
    Mar 2002
    Posts
    10
    PHP Code:
    void getboard (qtype item);
      { 
    ifstream sourcefile ("board.txt");
        
       if (
    sourcefile.fail())
          
    cerr << "Error opening board.txt...";
       else
          (while ! 
    sourcefile.eof());
             
    strcpy (item.board,"board.txt");
             
    getline(item.board);
                 
       
    sourcefile.close();
       return;
    }
    return 
    0
    strcpy() has two arguments, the destination char array comes first, then a comma, then the source char array. None of your calls to strcpy() follow that format. The source string presumably will come from the file you are reading, but your code never actually reads anything from file, that is there are no calls to >> or get() or getline() or whatever. Given the string is a title of a post or a question raised, there will probably be spaces embedded in the string so you will probably want to use getline() to read the file data in.
    So like this?

  5. #20
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    #include <frstream.h>  //I don't have an up to date compiler
    
    int main()
    {
      char FAQtitles[3][80];
      ofstream fout("FAQfile.txt");
      char dummy[80];
      char searchFor[80];
      int i;
      char continue = 'y';
      char found = 'n';
    
      //get input for the FAQ File, you can get this from where ever you
      // want.  
      for(i = 0; i < 3; i++)
      {
         cout << "enter FAQ title" << endl;
         cin.getline(dummy, 80);
         fout << dummy;
      }
    
      //user enters multidimensional arrays, File I/O, pointers for titles 
      //in FAQ file
    
      //open FAQfile for searching;
      ifstream fin("FAQfile.txt");
      
      //allow user to search FAQ file
      while(continue == 'y')
      {
         //obtain input to search the FAQ file for
         cout << "enter title to search the FAQ file for" << end;
         cin.getline(searchFor, 80);
        
        while(found == 'n' && fin)
        {
           fin.getline(dummy, 80);
           if(strcmp(dummy, searchFor) == 0)
           {
               found = 'y';
           }
         }
         
          //if found is n, then search failed, if found is y the search succeeded
         if(found == 'y')
         {
            cout << "title entered matches one of the titles in the FAQ   
                       file" << endl;
          }
          else 
              cout << "the title " << searchFor << " not found." << endl;
          
         //determine if user wishes to search further
         cout << "enter y to continue and any other key to stop" <<endl;
         cin >> continue;
        } 
    
      return 0;
    }

    The above (uncompiled and untested) program is an (over)simplistic demonstration regarding techniques that could be used to create and search a FAQ file. Because of the limitations regarding interpretting input, however, if the user searched the above FAQ file for the title "File I/O" the search should succeed, but if they entered "using Files" it wouldn't. Likewise if they searched using "2D arrays" rather than "multidimensional arrays" it wouldn't work. Even if they searched using "Mulitdimensional arrays" or "pointer" it wouldn't work (although thoe problems could be more readily overcome). This interpretation of input rather than simple equivalency testing is the biggest technical hurdle in the overall process. The techniques to do it are well outside the scope of my knowledge.

  6. #21
    Registered User
    Join Date
    Mar 2002
    Posts
    10

    You are skipping ahead

    I agree, the code for adapting this to FAQ searches will be complex, but we can slove that when we come to it.

    The focus right now should be on the first part of the problem.

    checking a particular webpage for a specific post,

    if it is not there, posting it,
    if it is there, going on to the next board.

    I think you are skipping forward to the really complex stuff, which I can help answer once I get a working knowlege of this language.

    I hope to attack this problem one step at a time.

    Load title, body and location
    check location for title
    if =='n' then post title and body

    I know, you want to do the fun stuff.

  7. #22
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Originally posted by salvelinus

    Forgot return 0;


    ...........
    ........

    .
    .
    .....
    .
    .....oh boohoo. I generated a warning. Time to jump off a bridge....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  2. ASP.net forum that supports Access
    By Grayson_Peddie in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-18-2003, 01:44 AM
  3. The Contest Forum has switched
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-16-2002, 03:10 PM
  4. Assembly forum
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-18-2001, 08:03 PM