Advertisement
Guest User

CALCULO DO TRIANGULO RETANGULO - VERSAO WEB

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