WhaleSpunk

Untitled

Apr 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7. void parse(char * equacao){
  8. //int i;
  9. char * i;
  10. char aux[20];
  11. char cToStr[2];
  12. cToStr[1] = '\0';
  13. char var[20];
  14. memset(var, 0, sizeof(var));
  15. memset(aux, 0, sizeof(aux));
  16. int num;
  17.  
  18. printf("equacao parse: %s\n",equacao);
  19. int flag=0;
  20. printf("dentro\n\n");
  21. //while(strcmp(equacao[i],"\n"
  22.  
  23. /*for(i=equacao; *i;i++){
  24. printf("i: %c\n",*i);
  25.  
  26. }*/
  27.  
  28. for(i=equacao; *i; i++){
  29. printf("entrou for\n");
  30. if(*i=='x'){
  31.  
  32. flag=1;
  33. }else{
  34. printf("inside i:%c\n",*i);
  35. if(flag==1){
  36. //posso guardar aux
  37. //vou identificar o x
  38.  
  39. if(*i=='-'||*i=='+'){
  40. printf("entrou if\n");
  41. printf("aux: %s \t-> X%s\n",aux,var);
  42. memset(var, 0, sizeof(var));
  43. memset(aux, 0, sizeof(aux));
  44. flag=0;
  45. cToStr[0] = *i;
  46. strcat(aux,cToStr);
  47. memset(cToStr, 0, sizeof(cToStr));
  48. cToStr[1] = '\0';
  49. }else{
  50. cToStr[0] = *i;
  51. strcat(var,cToStr);
  52. memset(cToStr, 0, sizeof(cToStr));
  53. cToStr[1] = '\0';
  54. }
  55.  
  56. }else{
  57. cToStr[0] = *i;
  58. strcat(aux,cToStr);
  59. memset(cToStr, 0, sizeof(cToStr));
  60. cToStr[1] = '\0';
  61. }
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68. }
  69. printf("aux: %s \t-> X%s\n",aux,var);
  70. }
  71.  
  72. int main()
  73. {
  74. char word[50];
  75. char equacao[150];
  76. char st[5];
  77. char statement[150];
  78. int flag=0;
  79.  
  80. while(scanf("%s",&word)!= EOF){
  81.  
  82. if(strcmp(word,"maximize")==0){
  83. flag=1;
  84. }
  85.  
  86. scanf("%s",&equacao);
  87. printf("word %s\n",word);
  88. printf("equacao %s\n", equacao);
  89. parse(equacao);
  90.  
  91. // if(strcmp(scanf("%s", &st),"st")==0){
  92. // while(strcmp(scanf("%s",&statement),"BINARY")!=0){
  93. //
  94. // }
  95. // }
  96.  
  97.  
  98. }
  99. }
Add Comment
Please, Sign In to add comment