?
Solved

Fairly Simple Search Engine question

Posted on 1997-06-02
3
Medium Priority
?
149 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 560 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

777 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