Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void parse(char * equacao){
- //int i;
- char * i;
- char aux[20];
- char cToStr[2];
- cToStr[1] = '\0';
- char var[20];
- memset(var, 0, sizeof(var));
- memset(aux, 0, sizeof(aux));
- int num;
- printf("equacao parse: %s\n",equacao);
- int flag=0;
- printf("dentro\n\n");
- //while(strcmp(equacao[i],"\n"
- /*for(i=equacao; *i;i++){
- printf("i: %c\n",*i);
- }*/
- for(i=equacao; *i; i++){
- printf("entrou for\n");
- if(*i=='x'){
- flag=1;
- }else{
- printf("inside i:%c\n",*i);
- if(flag==1){
- //posso guardar aux
- //vou identificar o x
- if(*i=='-'||*i=='+'){
- printf("entrou if\n");
- printf("aux: %s \t-> X%s\n",aux,var);
- memset(var, 0, sizeof(var));
- memset(aux, 0, sizeof(aux));
- flag=0;
- cToStr[0] = *i;
- strcat(aux,cToStr);
- memset(cToStr, 0, sizeof(cToStr));
- cToStr[1] = '\0';
- }else{
- cToStr[0] = *i;
- strcat(var,cToStr);
- memset(cToStr, 0, sizeof(cToStr));
- cToStr[1] = '\0';
- }
- }else{
- cToStr[0] = *i;
- strcat(aux,cToStr);
- memset(cToStr, 0, sizeof(cToStr));
- cToStr[1] = '\0';
- }
- }
- }
- printf("aux: %s \t-> X%s\n",aux,var);
- }
- int main()
- {
- char word[50];
- char equacao[150];
- char st[5];
- char statement[150];
- int flag=0;
- while(scanf("%s",&word)!= EOF){
- if(strcmp(word,"maximize")==0){
- flag=1;
- }
- scanf("%s",&equacao);
- printf("word %s\n",word);
- printf("equacao %s\n", equacao);
- parse(equacao);
- // if(strcmp(scanf("%s", &st),"st")==0){
- // while(strcmp(scanf("%s",&statement),"BINARY")!=0){
- //
- // }
- // }
- }
- }
Add Comment
Please, Sign In to add comment