Slide 3.4: Calling a CGI Perl script
Slide 3.6: Personal websites
Home

How to Construct the Exercise I (Cont.)

  1. File Processing Using C/C++ The Perl command system( LIST ) allows the host system to execute the command LIST. It is used here to call a C/C++ run file:
       system( "./CGIDemo '$name'" );
    where

    • CGIDemo is a C/C++ run file and
    • $name is the web input.

    The CGIDemo.cpp performs the following tasks:

    1. Reads the file cartoon.txt line-by-line.
    2. Check whether the line contains a substring $name.
    3. If it does, displays the line.

    ~wenchen/public_html/cgi-bin/351/week3/CGIDemo.cpp
    
    #include  <fstream>
    #include  <iostream>
    #include  <cstring>
      using namespace  std;
    
    int  main( int arc, char* argv[ ] ) {
      char     name[128]; 
      fstream  file; 
     
      file.open ( "cartoon.txt", fstream::in ); 
      while ( 1 ) { 
        file.getline( name, 128 ); 
        if ( file.eof( ) )  break; 
        if ( strstr( name, argv[1] ) != NULL ) 
          cout << "Found: <em>" << name << "</em><br />"; 
      } 
      file.close( );
    }

    You may check the results on the Web. For example, if you are using the previous CGI Perl script, the results will be shown at
      http://people.cs.und.edu/~wenchen/cgi-bin/351/week3/CGIDemo.pl