Solved

Fairly Simple Search Engine question

Posted on 1997-06-02
3
141 Views
Last Modified: 2013-12-25
We have been using a REXX script for searching our email database in the past.  However we would like to move to CGI to do this.  The problems I am having is the type of file we  had was 100's of names lined up like this:

>Jones, Scott
Email: here@there.com
>Johnson, Becky
Email: there@here.com

The '>' was there so the REXX script would know where to start looking for the name that was entered by the user.  Is there anyway we could convert this to a perl or C script to do the same thing, Returning the persons name and the next line (their email)?  Thanks in advance!

Dan
0
Comment
Question by:Primetyme
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 140 total points
ID: 1828174
Hello Dan,

one simple option is to code a sort of grep function that scans the file until it finds the right name; something like this:

--//--
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* search():
 * name: pointer to a string containing the name to look for
 * fp:   pointer to the file to scan (supposed already open for reading)
 *
 * returns a pointer to a string containing the e-mail address
 */

char *search(char *name, FILE *fp)
{
  char *buff;
  char str[BUFSIZ];

  if(!(buff = malloc(BUFSIZ))) /* malloc() failed! */
    return NULL;

  (void) rewind(fp) /* let's go to the BOF */

  sprintf(str, ">%s", name);

  while(fgets(buff, BUFSIZ, fp)) { /* get name line */
    if(strstr(buff, str)) /* found? */
      return fgets(buff, BUFSIZ, fp); /* return buff pointer */
    fgets(buff, BUFSIZ, fp); /* skeep e-mail line */
  }

  return NULL; /* name not found */
}
--//--

This should be enough for a hundred lines. If you still need faster performance, i'd suggest to build a simple C program to translate your database to a dbm (better ndbm) table.
I could give you some sample code for this too.

Rgds, julio
0
 

Author Comment

by:Primetyme
ID: 1828175
I would really appreciate some sort of code in C since that
is what I am more familiar with :)  and do i need to have the
.txt file with all these names in the same dir? (it is) Thanks
again :)

Dan
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1828176
Well, that _was_ C code! :)

Really, are you asking for a complete working CGI code, going with the sequential method just shown?

If so, it's ok: do you prefer GET or POST method?

Don't worry about where to put the text file.

BTW, maybe this could be worth a bit more points.

Cheers, julio
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now