C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 26th, 2003, 10:19 AM
PJG PJG is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Ireland
Posts: 1 PJG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question help with CGI script in C

I have the following code written to search a document for occurances of a string ( eventually will be searching a folder of documents, but thats another problem)
This code works perfect when compiled in Visual C++ but when I try to convert to cgi, the first strstr line lets me down......absolutely lost on this one......
Cheers............................PJG
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLEN 80
#define EXTRA 5 /* 4 for field name "data", 1 for "=" */
#define MAXINPUT MAXLEN+EXTRA+2 /* 1 for added line break, 1 for trailing NUL */


void unencode(char *src, char *last, char *dest)
{
for(; src != last; src++, dest++)
if(*src == '+')
*dest = ' ';
else if(*src == '%') {
int code;
if(sscanf(src+1, "%2x", &code) != 1) code = '?';
*dest = code;
src +=2; }
else
*dest = *src;
*dest = '\n';
*++dest = '\0';
}


int main(void)
{ /* begin program */



char line[250];
const char *delimiters = {" \t \n "};
char *token=NULL;
char* pStr = NULL;
int count = 0, line_count=0;
char *test = "";
FILE *essay;
char *lenstr;
char input[MAXINPUT], data[MAXINPUT];
long len;


printf("%s%c%c\n",
"Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<TITLE>Response</TITLE>\n");


lenstr = getenv("CONTENT_LENGTH"); /* Getting string from HTML page */

if(lenstr == NULL || sscanf(lenstr,"%ld",&len)!=1 || len > MAXLEN) /*verifying that string is valid*/
printf("<P>Error in invocation - wrong FORM probably.");


else { /* begin ELSE */

fgets(input, len+1, stdin);
unencode(input+EXTRA, input+len, data);



if ((essay = fopen("C:/Inetpub/wwwroot/cgi-bin/stroke.txt", "r")) == NULL )
{
printf("<h2>File could not be opened - ask yourself WHYYYYY?");
}
else



while (!feof(essay))
{
if( fgets(line, 250, essay) != NULL )
{


pStr = line;
line_count++;


if (( test = strtok(pStr, delimiters )) != NULL )
{

if(strstr(test,data) !=NULL)



{

count++;
printf("<P>Entry %d on line %d: %s<br>", count, line_count, data);
}

while (( test = strtok((char *)NULL, delimiters )) != NULL)
{
if ( strstr(test,data) != NULL)
{
count++;
printf("<P> Entry %d on line %d: %s<br>", count, line_count, data);
}
}
}
}


}

printf("<H3>Files were searched successfully.... how about that!");
printf("<P>The string <H4>%s</H4> occurs %d times in %s <BR>", data, count, essay);

fclose(essay);

count =0;


}


return 0;
} /* End Program */

Reply With Quote
  #2  
Old March 7th, 2003, 03:05 AM
operator smooth operator smooth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 61 operator smooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Does it work if you do not call unencode() ?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > help with CGI script in C


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway