Advertisement
Guest User

CALCULO DO TRIANGULO RETANGULO - VERSAO WEB

a guest
May 21st, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1.  
  2. // CALCULO DO TRIANGULO RETANGULO - VERSAO WEB //
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8.  
  9. char* corta(const char* parm_s1, char* s2, int f)
  10. {
  11.     if (!strlen(parm_s1))
  12.     return NULL;
  13.  
  14.     int l;
  15.     char* t1;
  16.     char* s1=strdup(parm_s1);
  17.     char* p=(char*)strtok_r(s1,s2,&t1);
  18.  
  19.     if (!p)
  20.       return NULL;
  21.    
  22.     int n=0;
  23.     while (p)
  24.     {
  25.         n++;
  26.         if (n==f)
  27.             return p;
  28.         p=(char*)strtok_r(NULL,s2,&t1);
  29.     }
  30.     return NULL;
  31. }
  32.  
  33. void cabecalho()
  34. {
  35.      printf("Content-type: text/html\n\n");
  36.      printf("<meta charset=\"ISO-8859-1\">\n");
  37. }
  38.  
  39. void calcula(char* p)
  40. {
  41.     float area,base,altura;
  42.  
  43.     base=atof(corta(corta(p,"&",1),"=",2));
  44.     printf("Base=%f<br>",base);
  45.  
  46.     altura=atof(corta(corta(p,"&",2),"=",2));
  47.     printf("Altura=%f<br>",altura);
  48.  
  49.     area=(base*altura)/2;
  50.     printf("Area=%f<br>",area);
  51.  
  52. }
  53.  
  54. void comprimento(char* p2)
  55. {
  56.     strlen(p2) ? calcula(p2) : 0;
  57. }
  58.  
  59. void get()
  60. {
  61.     char* p2=getenv("QUERY_STRING");
  62.         p2 ? comprimento(p2) : 0;
  63. }
  64.  
  65. void cgi()
  66. {
  67.   cabecalho();
  68.   get();
  69. }
  70.  
  71. int main()
  72. {
  73.   cgi();
  74. }
  75.  
  76. // Compilando : cc -o /cgi-bin/cgi cgi.c
  77. // 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