make it simpler and efficient

Posted by gcc on Stack Overflow See other posts from Stack Overflow or by gcc
Published on 2010-05-09T16:30:37Z Indexed on 2010/05/09 16:38 UTC
Read the original article Hit count: 121

Filed under:
|
|
 temp1=*tutar[1];          //i hold input in char *tutar[]
     if(temp1!='x'||temp1!='n')
   arrays[1]=malloc(sizeof(int)*num_arrays); //if second input is int  
     a=0;
    n=i;
    for(i=1;i<n;++i)      
        {           
     temp1=*tutar[i];    
     if(temp1=='d')
        {   ++i;
            j=atoi(tutar[i]);
            free(arrays[j]);
            continue;
        }
     if(temp1=='x')
        break;
     if(temp1=='n')//if it is n 
      {  a=0;          
         ++j;    
        arrays[j]=malloc(sizeof(int)*num_arrays);//create and allocate 
          continue;
      }          
      ++a;
     if(a>num_arrays)    //resize the array
         arrays[j]=realloc(arrays[j],sizeof(int)*(num_arrays+a));


         *(arrays[j]+a-1)=atoi(tutar[i]);

    printf("%d",arrays[1][1]);
       }


            arrays is pointer
  when you see x exit   
       you see n create (old one is new array[a]  new one is array[i+1])
       you see d delete arrays[i]  according to int after d
       first number is size of max arrays

and where is the error in code input is composed from int and n d x

i make a program 
   -taking input(first input must be int)
   -according to input(there is comman in input like n or d or j , i fill array with number and use memory efficiently
   -j is jumb to array[x] ( x is int coming after j in input)

© Stack Overflow or respective owner

Related posts about c

    Related posts about error