Free for PREMIUM members
Submit
Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium
Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
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
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
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