G
Greg
I am writing the basics of a cgi program in C. I am getting a wierd
segmentation fault with the following code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 80
/* function prototypes */
void parseParams (char *) ;
void parseQString (char *) ;
void unencode (char *, char *, char *) ;
int main (void) {
char *params = getenv ("QUERY_STRING") ;
char *paramCounter ;
char copy [MAXLEN] ;
int numParams = 0 ;
printf ("%s\n", params) ; // SEG FAULT HERE
// content header
printf("%s\n\n","Content-Type:text/plain");
parseQString (params) ;
return 0 ;
}
void parseQString (char *q_str) {
char *ptr = q_str ;
printf ("%s\n", ptr) ;
while (*ptr != '\0') {
printf ("%c\n", *ptr) ;
ptr++ ;
}
}
When I try to print out the contents of params in the main program, I
get a segmentation fault. However, when I print out the contents in
the parseQString function, there is no problem at all. Does anyone
have any idea why it would give me an error in one place but not the
other?
Thanks
Greg
segmentation fault with the following code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 80
/* function prototypes */
void parseParams (char *) ;
void parseQString (char *) ;
void unencode (char *, char *, char *) ;
int main (void) {
char *params = getenv ("QUERY_STRING") ;
char *paramCounter ;
char copy [MAXLEN] ;
int numParams = 0 ;
printf ("%s\n", params) ; // SEG FAULT HERE
// content header
printf("%s\n\n","Content-Type:text/plain");
parseQString (params) ;
return 0 ;
}
void parseQString (char *q_str) {
char *ptr = q_str ;
printf ("%s\n", ptr) ;
while (*ptr != '\0') {
printf ("%c\n", *ptr) ;
ptr++ ;
}
}
When I try to print out the contents of params in the main program, I
get a segmentation fault. However, when I print out the contents in
the parseQString function, there is no problem at all. Does anyone
have any idea why it would give me an error in one place but not the
other?
Thanks
Greg