WhaleSpunk

Untitled

Apr 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. void parse(char * equacao, int type, int index){
  7. //int i;
  8. char * i;
  9. char aux[20];
  10. char cToStr[2];
  11. cToStr[1] = '\0';
  12. char var[20];
  13. char operation[20];
  14. char res[20];
  15. memset(var, 0, sizeof(var));
  16. memset(aux, 0, sizeof(aux));
  17. memset(operation, 0, sizeof(aux));
  18. memset(res, 0, sizeof(aux));
  19. int num;
  20.  
  21. printf("equacao parse: %s\n",equacao);
  22. int flag=0;
  23. int flag2=0;
  24. printf("dentro\n\n");
  25. //while(strcmp(equacao[i],"\n"
  26.  
  27. /*for(i=equacao; *i;i++){
  28. printf("i: %c\n",*i);
  29.  
  30. }*/
  31.  
  32. for(i=equacao; *i; i++){
  33. printf("entrou for\n");
  34. if(*i=='x'){
  35.  
  36. flag=1;
  37. }else{
  38. printf("inside i:%c\n",*i);
  39. if(flag==1){
  40. //posso guardar aux
  41. //vou identificar o x
  42.  
  43. if(*i=='-'||*i=='+'){
  44. printf("entrou if\n");
  45. printf("aux: %s \t-> X%s\n",aux,var);
  46. memset(var, 0, sizeof(var));
  47. memset(aux, 0, sizeof(aux));
  48. flag=0;
  49. cToStr[0] = *i;
  50. strcat(aux,cToStr);
  51. memset(cToStr, 0, sizeof(cToStr));
  52. cToStr[1] = '\0';
  53. }else{
  54.  
  55. if(*i == '<'||*i=='>'||*i=='='||flag2==1){
  56. flag2=1;
  57. if(operation[0] == '=' || operation[1]=='='){
  58.  
  59. cToStr[0] = *i;
  60. strcat(res,cToStr);
  61. memset(cToStr, 0, sizeof(cToStr));
  62. cToStr[1] = '\0';
  63.  
  64. }else{
  65. cToStr[0] = *i;
  66. strcat(operation,cToStr);
  67. memset(cToStr, 0, sizeof(cToStr));
  68. cToStr[1] = '\0';
  69. }
  70.  
  71.  
  72.  
  73. }else{
  74. cToStr[0] = *i;
  75. strcat(var,cToStr);
  76. memset(cToStr, 0, sizeof(cToStr));
  77. cToStr[1] = '\0';
  78. }
  79. }
  80.  
  81. }else{
  82.  
  83. cToStr[0] = *i;
  84. strcat(aux,cToStr);
  85. memset(cToStr, 0, sizeof(cToStr));
  86. cToStr[1] = '\0';
  87. }
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94. } if(type == 1){
  95.  
  96. printf("aux: %s \t-> X%s \t -> %s \t ->%s\n",aux,var,operation, res);
  97.  
  98. }
  99. else{
  100.  
  101. printf("aux: %s \t-> X%s\n",aux,var);
  102. }
  103.  
  104. }
  105.  
  106. int main()
  107. {
  108. char word[50];
  109. char equacao[150];
  110. char st[5];
  111. char statement[150];
  112. int flag=0;
  113. int i=0;
  114.  
  115. while(scanf("%s",&word)!= EOF){
  116.  
  117. if(strcmp(word,"maximize")==0){
  118. flag=1;
  119. }
  120.  
  121. scanf("%s",&equacao);
  122. printf("word %s\n",word);
  123. printf("equacao %s\n", equacao);
  124. parse(equacao, 0,i);
  125. i++;
  126. scanf("%s", &st);
  127. if(strcmp(st,"st")==0){
  128. printf("\n------------STS----------\n");
  129. scanf("%s",&statement);
  130.  
  131. while(strcmp(statement,"BINARY")!=0){
  132.  
  133. printf("->Statement: %s\n", statement);
  134. parse(statement,1,i);
  135. i++;
  136.  
  137.  
  138. scanf("%s",&statement);
  139. }
  140. }
  141.  
  142.  
  143. }
  144. }
Add Comment
Please, Sign In to add comment