Solved

Fairly Simple Search Engine question

Posted on 1997-06-02
3
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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