Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CALCULO DO TRIANGULO RETANGULO - VERSAO WEB //
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- char* corta(const char* parm_s1, char* s2, int f)
- {
- if (!strlen(parm_s1))
- return NULL;
- int l;
- char* t1;
- char* s1=strdup(parm_s1);
- char* p=(char*)strtok_r(s1,s2,&t1);
- if (!p)
- return NULL;
- int n=0;
- while (p)
- {
- n++;
- if (n==f)
- return p;
- p=(char*)strtok_r(NULL,s2,&t1);
- }
- return NULL;
- }
- void cabecalho()
- {
- printf("Content-type: text/html\n\n");
- printf("<meta charset=\"ISO-8859-1\">\n");
- }
- void calcula(char* p)
- {
- float area,base,altura;
- base=atof(corta(corta(p,"&",1),"=",2));
- printf("Base=%f<br>",base);
- altura=atof(corta(corta(p,"&",2),"=",2));
- printf("Altura=%f<br>",altura);
- area=(base*altura)/2;
- printf("Area=%f<br>",area);
- }
- void comprimento(char* p2)
- {
- strlen(p2) ? calcula(p2) : 0;
- }
- void get()
- {
- char* p2=getenv("QUERY_STRING");
- p2 ? comprimento(p2) : 0;
- }
- void cgi()
- {
- cabecalho();
- get();
- }
- int main()
- {
- cgi();
- }
- // Compilando : cc -o /cgi-bin/cgi cgi.c
- // Executando : links -dump "http://172.16.17.1:777/cgi-bin/cgi?base=20&altura=30"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement