Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *funct1(char *op1)
- {
- int lenght,a,b,i,j,k=0,lnum[500],result=0;
- char aux[100],result_string[500];
- lenght=strlen(op1);
- for(i=0; i<lenght; i++)
- {
- if((op1[i]>='0')&&(op1[i]<='9'))
- {
- /*printf("\nEste caracter es numero. ");*/
- for(j=0; j<lenght; j++)
- {
- if((op1[i+j]>='0')&&(op1[i+j]<='9'))
- {
- /*printf("%c",op1[i+j]);*/
- aux[j]=op1[i+j];
- }
- else
- {
- aux[j]=NULL;
- i=i+j-1;//evita que parsee de nuevo al tener ya numeros grandes.
- break;
- }
- }
- sscanf(aux,"%i",&a);
- /*printf("\nConvertido a entero, es %i",a);*/
- }
- else
- {
- aux[0]=NULL;
- k=i+1;
- for(j=0; j+k<lenght; j++)
- {
- if((op1[k+j]>='0')&&(op1[k+j]<='9'))
- {
- /*printf("%c",op1[i+j]);*/
- aux[j]=op1[k+j];
- }
- else
- {
- //i=i+j-1;//evita que parsee de nuevo al
- //tener ya numeros grandes.
- break;
- }
- }
- aux[j]=NULL;
- sscanf(aux,"%i",&b);
- /*printf("\n(%s)b=%i\n",aux,b);*/
- //ASINGNAR!!
- /*printf("\nEl caracter %c no es numero. ",op1[i]);*/
- //Guarda los valores a usar aca
- if(op1[i]=='+')
- {
- result=a+b;
- printf("\nEl resultado es %i",result);
- }
- if(op1[i]=='-')
- {
- result=a-b;
- printf("\nEl resultado es %i",result);
- }
- if(op1[i]=='*')
- {
- result=a*b;
- printf("\nEl resultado es %i",result);
- }
- if(op1[i]=='/')
- {
- result=a/b;
- printf("\nEl resultado es %i",result);
- }
- i=i+j+1;
- break;
- }
- }
- sprintf(result_string,"%i",result);
- k=strlen(result_string);
- for(j=0; j+i<lenght; j++)
- {
- result_string[j+k]=op1[i+j];
- }
- result_string[j+k]=NULL;
- printf("\nLa cadena resultante es %s",result_string);
- return result_string;
- }
- int verifier(char *op1)
- {
- int lenght,i;
- lenght=strlen(op1);
- for(i=0; i<lenght; i++)
- {
- if((op1[i]=='+')||(op1[i]=='-')||(op1[i]=='*')||(op1[i]=='/'))
- return 1;
- }
- return 0;
- }
- int main()
- {
- char op[500],*res_string;
- fflush(stdin);
- scanf("%s",op);
- do
- {
- res_string=funct1(op);
- strcpy(op,res_string);
- }
- while(verifier(res_string));
- printf("\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment