Guest User

Untitled

a guest
Nov 18th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. char *funct1(char *op1)
  7. {
  8.     int lenght,a,b,i,j,k=0,lnum[500],result=0;
  9.     char aux[100],result_string[500];
  10.     lenght=strlen(op1);
  11.     for(i=0; i<lenght; i++)
  12.     {
  13.  
  14.         if((op1[i]>='0')&&(op1[i]<='9'))
  15.         {
  16.             /*printf("\nEste caracter es numero. ");*/
  17.             for(j=0; j<lenght; j++)
  18.             {
  19.                 if((op1[i+j]>='0')&&(op1[i+j]<='9'))
  20.                 {
  21.                     /*printf("%c",op1[i+j]);*/
  22.                     aux[j]=op1[i+j];
  23.                 }
  24.                 else
  25.                 {
  26.                     aux[j]=NULL;
  27.                     i=i+j-1;//evita que parsee de nuevo al tener ya numeros grandes.
  28.                     break;
  29.                 }
  30.             }
  31.             sscanf(aux,"%i",&a);
  32.             /*printf("\nConvertido a entero, es %i",a);*/
  33.  
  34.         }
  35.  
  36.         else
  37.         {
  38.             aux[0]=NULL;
  39.             k=i+1;
  40.             for(j=0; j+k<lenght; j++)
  41.             {
  42.                 if((op1[k+j]>='0')&&(op1[k+j]<='9'))
  43.                 {
  44.                     /*printf("%c",op1[i+j]);*/
  45.                     aux[j]=op1[k+j];
  46.                 }
  47.                 else
  48.                 {
  49.  
  50.                     //i=i+j-1;//evita que parsee de nuevo al
  51.                     //tener ya numeros grandes.
  52.                     break;
  53.                 }
  54.             }
  55.             aux[j]=NULL;
  56.             sscanf(aux,"%i",&b);
  57.             /*printf("\n(%s)b=%i\n",aux,b);*/
  58.             //ASINGNAR!!
  59.             /*printf("\nEl caracter %c no es numero. ",op1[i]);*/
  60.             //Guarda los valores a usar aca
  61.             if(op1[i]=='+')
  62.             {
  63.                 result=a+b;
  64.                 printf("\nEl resultado es %i",result);
  65.             }
  66.  
  67.  
  68.             if(op1[i]=='-')
  69.             {
  70.                 result=a-b;
  71.                 printf("\nEl resultado es %i",result);
  72.             }
  73.  
  74.             if(op1[i]=='*')
  75.             {
  76.                 result=a*b;
  77.                 printf("\nEl resultado es %i",result);
  78.             }
  79.  
  80.             if(op1[i]=='/')
  81.             {
  82.                 result=a/b;
  83.                 printf("\nEl resultado es %i",result);
  84.             }
  85.             i=i+j+1;
  86.             break;
  87.  
  88.         }
  89.     }
  90.     sprintf(result_string,"%i",result);
  91.     k=strlen(result_string);
  92.  
  93.     for(j=0; j+i<lenght; j++)
  94.     {
  95.         result_string[j+k]=op1[i+j];
  96.     }
  97.     result_string[j+k]=NULL;
  98.     printf("\nLa cadena resultante es %s",result_string);
  99.  
  100.     return result_string;
  101. }
  102.  
  103. int verifier(char *op1)
  104. {
  105.     int lenght,i;
  106.     lenght=strlen(op1);
  107.  
  108.     for(i=0; i<lenght; i++)
  109.     {
  110.         if((op1[i]=='+')||(op1[i]=='-')||(op1[i]=='*')||(op1[i]=='/'))
  111.             return 1;
  112.     }
  113.     return 0;
  114. }
  115.  
  116. int main()
  117. {
  118.     char op[500],*res_string;
  119.  
  120.     fflush(stdin);
  121.     scanf("%s",op);
  122.     do
  123.     {
  124.         res_string=funct1(op);
  125.         strcpy(op,res_string);
  126.     }
  127.     while(verifier(res_string));
  128.     printf("\n\n");
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment