B
bpascal123
Hi cyberusers
I have learned the basic of C programming a while ago but left for something closer to my job. Now I feel my job is getting close to web programming so i decided to see the basic of web programming.
I encounter this message
Error 500: Script Execution Failure
the web url : http://multiskillz.tekcities.com
(just to warn you there is a google javascript that monitor traffic and another one for the same purpose but not on everypage, anyway nothing else, I coded everything using a text editor...)
For reference, the script below is almost entirely inspired from this website :
http://www.lamsade.dauphine.fr/rigaux/mysqlphp/index.php?page=exemples
This is the script I'm trying to run
I saved it under name "k5001_tuto1ExCgi.cgi"
----------c cgi code start----------
#include <stdio.h>
#include <stdlib.h>
#define MAXL 132
char * ExtraitArg(char* ligne, char *arg);
/*int main(void){*/
int main(int arg, char* argv[]){
int nbFilms=0, anMin, anMax=0, annee_naissance;
char titre[40], film[40], nom[40], prenom[40], comb[3];
int annee, lg;
FILE *films;
char ligne[MAXL], arg[MAXL];
short bonTitre=0, bonnePeriode=0;
printf("Content-type: text/html\n\n");
printf("<HEAD><TITLE>Resultat de la recherche</TITLE>");
printf("</HEAD><BODY bgcolor=white>");
printf("<H1><CENTER>Resultat de la recherche</CENTER></H1>")
/***PHASE 1 EXTRACTION DES PARAMETRES dasn chaine ligne***/
lg = atoi(getenv("CONTENT_LENGTH"));
fgets(ligne, lg+1, stdin);
printf("<B>Parametres : </B> %s<P>\n", ligne);
strcpy(ligne, ExtraitArg(ligne,titre));
strcpy(ligne, ExtraitArg(ligne,arg));
anMin = atoi(arg);
strcpy(ligne, ExtraitArg(ligne,titre));
anMax = atoi(arg);
strcpy(ligne, ExtraitArg(ligne,comb));
printf("<HR><P><B>Recherche:</B>Titre=%s %s annee de %d a %d<br /><HR>", titre, comb, anMin, anMax);
/*Phase 2 rech et affi */
films = fopen("k4000_films.txt", "r");
while(fgets(ligne, MAXL, films)){
sscanf(ligne, "%s %d %s %s %d", film, &annee, nom, prenom, &annee_naissance);
if(!strcmp(film, titre)) bontitre = 1;
if(annee >= anMin && annee <= anMax) bonnePeriode = 1;
if((!strcmp("AND", comb) && bonTitre && bonnePeriode) || (!strcmp("OR", comb) && (bonTitre || bonnePeriode))){
nbFilms++;
printf("<b>Film:</b> %s, %d, de %s %s <br />", film, annee, prenom, nom);
}
bonTitre=0;
bonnePeriode=0;
}
fclose(films);
if(!nbFilms) printf("<b>No films found!</b>");
return 1;
}
/***FUNCTION USED IN MAIN ***/
char* ExtraitArg(char* ligne, char *arg){
int pos = 0, posArg = 0;
while (ligne[pos++] != '=');
while (ligne[pos] != '&' && ligne[pos] != '\0')
arg[posArg++] = ligne[pos++];
arg[posArg] = '\0';
return &(ligne[pos+1]);
}
----------c cgi code end----------
the html form for the script
------------HTML start------------
<FORM ACTION = 'http://multiskillz.tekcities.com/cgi-bin/k5001_tuto1ExCgi..cgi' METHOD=POST>
<p><i>Search info from this form using cgi script</i></p>
<br />
<p>Title <INPUT TYPE='TEXT' SIZE=20 NAME='titre'></p>
<br />
<p>Starting year <INPUT TYPE='TEXT' SIZE=4 NAME='anMin' VALUE=1900>       
Ending year <INPUT TYPE='TEXT' SIZE=4 NAME='anMax' VALUE=2100></p>
<br />
<p><b>Combine search criteria</b>    
<i>AND</i>   <INPUT TYPE='RADIO' NAME='comb' VALUE='AND' CHECKED>   
<i>OR</i>   <INPUT TYPE='RADIO' NAME='comb' VALUE='OR'> ? </p>
<br />
<p><INPUT TYPE='SUBMIT' VALUE=' Search '>
</FORM>
</CENTER>
------------HTML end------------
and the text file k4000_films.txt
---txt start---
Alien 1979 Scott Ridley 1943
Vertigo 1958 Hitchcock Alfred 1899
Psychose 1960 Hitchcock Alfred 1899
Kagemusha 1980 Kurosawa Akira 1910
Volte-face 1997 Woo John 1946
Titanic 1997 Cameron James 1954
Sacrifice 1986 Tarkovski Andrei 1932
---txt ends---
Does something see something that makes the script not run? There are a fewother files I had to amend in the author website so maybe it's same here. At least it's good practice.
Variable names are in French, I can change that if that helps. In the c file, I am not well versed with sscanf and file reading, however the annee variable which means 'year' in French is declared as int type. As the text file is displayed in this way Alien 1979 Scott Ridley 1943Vertigo, (in a single line) however if you copy paste there is a carriage return, I don't know if it's '\n' or '\r' but I am not sure if it doesn't mess with the variable'film' which is declared as a 40 characters array. I am not sure if that'sthe reason. Anything else, it's difficult to debug unless I compiled and run it locally. I'm not even sure if I can access a simple c compiler on windows 7. Please advise.
Thank in advance
Regards
Pascal
I have learned the basic of C programming a while ago but left for something closer to my job. Now I feel my job is getting close to web programming so i decided to see the basic of web programming.
I encounter this message
Error 500: Script Execution Failure
the web url : http://multiskillz.tekcities.com
(just to warn you there is a google javascript that monitor traffic and another one for the same purpose but not on everypage, anyway nothing else, I coded everything using a text editor...)
For reference, the script below is almost entirely inspired from this website :
http://www.lamsade.dauphine.fr/rigaux/mysqlphp/index.php?page=exemples
This is the script I'm trying to run
I saved it under name "k5001_tuto1ExCgi.cgi"
----------c cgi code start----------
#include <stdio.h>
#include <stdlib.h>
#define MAXL 132
char * ExtraitArg(char* ligne, char *arg);
/*int main(void){*/
int main(int arg, char* argv[]){
int nbFilms=0, anMin, anMax=0, annee_naissance;
char titre[40], film[40], nom[40], prenom[40], comb[3];
int annee, lg;
FILE *films;
char ligne[MAXL], arg[MAXL];
short bonTitre=0, bonnePeriode=0;
printf("Content-type: text/html\n\n");
printf("<HEAD><TITLE>Resultat de la recherche</TITLE>");
printf("</HEAD><BODY bgcolor=white>");
printf("<H1><CENTER>Resultat de la recherche</CENTER></H1>")
/***PHASE 1 EXTRACTION DES PARAMETRES dasn chaine ligne***/
lg = atoi(getenv("CONTENT_LENGTH"));
fgets(ligne, lg+1, stdin);
printf("<B>Parametres : </B> %s<P>\n", ligne);
strcpy(ligne, ExtraitArg(ligne,titre));
strcpy(ligne, ExtraitArg(ligne,arg));
anMin = atoi(arg);
strcpy(ligne, ExtraitArg(ligne,titre));
anMax = atoi(arg);
strcpy(ligne, ExtraitArg(ligne,comb));
printf("<HR><P><B>Recherche:</B>Titre=%s %s annee de %d a %d<br /><HR>", titre, comb, anMin, anMax);
/*Phase 2 rech et affi */
films = fopen("k4000_films.txt", "r");
while(fgets(ligne, MAXL, films)){
sscanf(ligne, "%s %d %s %s %d", film, &annee, nom, prenom, &annee_naissance);
if(!strcmp(film, titre)) bontitre = 1;
if(annee >= anMin && annee <= anMax) bonnePeriode = 1;
if((!strcmp("AND", comb) && bonTitre && bonnePeriode) || (!strcmp("OR", comb) && (bonTitre || bonnePeriode))){
nbFilms++;
printf("<b>Film:</b> %s, %d, de %s %s <br />", film, annee, prenom, nom);
}
bonTitre=0;
bonnePeriode=0;
}
fclose(films);
if(!nbFilms) printf("<b>No films found!</b>");
return 1;
}
/***FUNCTION USED IN MAIN ***/
char* ExtraitArg(char* ligne, char *arg){
int pos = 0, posArg = 0;
while (ligne[pos++] != '=');
while (ligne[pos] != '&' && ligne[pos] != '\0')
arg[posArg++] = ligne[pos++];
arg[posArg] = '\0';
return &(ligne[pos+1]);
}
----------c cgi code end----------
the html form for the script
------------HTML start------------
<FORM ACTION = 'http://multiskillz.tekcities.com/cgi-bin/k5001_tuto1ExCgi..cgi' METHOD=POST>
<p><i>Search info from this form using cgi script</i></p>
<br />
<p>Title <INPUT TYPE='TEXT' SIZE=20 NAME='titre'></p>
<br />
<p>Starting year <INPUT TYPE='TEXT' SIZE=4 NAME='anMin' VALUE=1900>       
Ending year <INPUT TYPE='TEXT' SIZE=4 NAME='anMax' VALUE=2100></p>
<br />
<p><b>Combine search criteria</b>    
<i>AND</i>   <INPUT TYPE='RADIO' NAME='comb' VALUE='AND' CHECKED>   
<i>OR</i>   <INPUT TYPE='RADIO' NAME='comb' VALUE='OR'> ? </p>
<br />
<p><INPUT TYPE='SUBMIT' VALUE=' Search '>
</FORM>
</CENTER>
------------HTML end------------
and the text file k4000_films.txt
---txt start---
Alien 1979 Scott Ridley 1943
Vertigo 1958 Hitchcock Alfred 1899
Psychose 1960 Hitchcock Alfred 1899
Kagemusha 1980 Kurosawa Akira 1910
Volte-face 1997 Woo John 1946
Titanic 1997 Cameron James 1954
Sacrifice 1986 Tarkovski Andrei 1932
---txt ends---
Does something see something that makes the script not run? There are a fewother files I had to amend in the author website so maybe it's same here. At least it's good practice.
Variable names are in French, I can change that if that helps. In the c file, I am not well versed with sscanf and file reading, however the annee variable which means 'year' in French is declared as int type. As the text file is displayed in this way Alien 1979 Scott Ridley 1943Vertigo, (in a single line) however if you copy paste there is a carriage return, I don't know if it's '\n' or '\r' but I am not sure if it doesn't mess with the variable'film' which is declared as a 40 characters array. I am not sure if that'sthe reason. Anything else, it's difficult to debug unless I compiled and run it locally. I'm not even sure if I can access a simple c compiler on windows 7. Please advise.
Thank in advance
Regards
Pascal