2
This commit is contained in:
27
server-exp2/cgi-bin/add.c
Normal file
27
server-exp2/cgi-bin/add.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define MAXLINE 8192
|
||||
|
||||
int main(void) {
|
||||
char *buf, *p;
|
||||
char content[MAXLINE];
|
||||
int n1=0, n2=0;
|
||||
|
||||
/* Extract the two arguments from standard input */
|
||||
scanf("%d&%d", &n1, &n2);
|
||||
|
||||
/* Make the response body */
|
||||
sprintf(content, "Welcome to add.com: ");
|
||||
sprintf(content, "%sTHE Internet addition portal.\r\n<p>", content);
|
||||
sprintf(content, "%sThe answer is: %d + %d = %d\r\n<p>",
|
||||
content, n1, n2, n1 + n2);
|
||||
sprintf(content, "%sThanks for visiting!\r\n", content);
|
||||
|
||||
/* Generate the HTTP response */
|
||||
printf("Content-length: %d\r\n", (int) strlen(content));
|
||||
printf("Content-type: text/html\r\n\r\n");
|
||||
printf("%s", content);
|
||||
fflush(stdout);
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user