Help me! indentation problem

This is a discussion on Help me! indentation problem within the C Programming forums, part of the General Programming Boards category; I m using DEVcpp. I have auto indentation generated like this. i want to fix my tab and to 4 ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    Help me! indentation problem

    I m using DEVcpp. I have auto indentation generated like this.

    i want to fix my tab and to 4 spaces.... plz help...

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    //-----------------------------------------------
    
    //-- inputarray defi --
    void inputarray(int size, double* array){
         
         int a=0;
         for(; a<size; a++){
               printf("Enter Value %d: ",a+1);
               scanf("%lf",(array+a));
                            }   
                             
    }
    // ** inputarray end **
    
    //----------------------------------------------
    
    //-- printarray defi --
    void printarray(int size, double* array){
         
         int a=0;
         for(; a<size; a++){
               printf("%lf\n",*(array+a));
                            }     
    }
    // ** printarray end **
    
    //------------------------------------------------
    
    // ** inputarray end **
    
    
    //-- sortarray defi --
    void sortarray(int size, double* array, char order)
    {
         int a=0,b=0,chck=0;
         double temp=0;
    
    // -------Swith Case Start-------
    
         switch(order){
                    case 'A':
                    case 'a':
                         for(b=0; b<size; b++){
                               chck=0;
                                for(a=0; a<size-1;a++){
                                     
                                     if(*(array+a)>*(array+a+1)){
                                                        chck++;
                                                        temp=*(array+a);
                                                        *(array+a)=*(array+a+1);
                                                        *(array+a+1)=temp;
                                                        }
                                          }
                                         if(chck == 0)
                                         break;
                                          }
                                         break;
         
                   case 'D':
                   case 'd':
                           for(b=0; b<size; b++){
                               chck=0;
                                for(a=0; a<size-1;a++){
                                     
                                     if(*(array+a)<*(array+a+1))
                                                       {
                                                        chck++;
                                                        temp=*(array+a);
                                                        *(array+a)=*(array+a+1);
                                                        *(array+a+1)=temp;
                                                        }
                                          
                                          
                                          }
                                         if(chck == 0)
                                         break;
                                          }
                                          }
                                                 
    //--------------Switch case end--------------                
                    
    }
                       
    // ** sortarray end **
    
    //-----------------------------------------------
    
    // ** mergeandsortarray definition **
    
    void mergeandsortarray(int size1, double* arr1, int size2, double* arr2, double* arr3){
         
        int a=0,b=0,c=0;
        //int size3=size1+size2,i=0,z=0,q=0;
         sortarray(size1,arr1,'D');
         sortarray(size2,arr2,'D');               
         
         while(a != size1 || b != size2){
                   if( *(arr1+a) > *(arr2+b)){
                       *(arr3+c)=*(arr1+a);
                       a++;
                                              }
                   else{
                        *(arr3+c)=*(arr2+b);
                        b++;
                        }
                   c++;
                                            }  
    }
    
    // --mergeandsortarray end--
    
    //-----------------------------------------------
    
    //-- int main --
    int main()
    {
        double *arr1, *arr2, *arr3;
        int size1,size2,size3;
        char order;
    
    //Array 1 Functions
        
        printf("\nEnter the size of array 1: ");
        scanf("%d",&size1);
        
        arr1=(double *)malloc(size1*sizeof(double));
        
        inputarray(size1,arr1);
        sortarray(size1,arr1,'D');
        
        
    //Array 2 Functions    
        
        printf("\nEnter the size of array 2: ");
        scanf("%d",&size2);
        
        arr2=(double *)malloc(size2*sizeof(double));
        
        inputarray(size2,arr2);
        sortarray(size2,arr2,'D');
        
    //Array 3 Functions
        size3=size1+size2;
        arr3=(double *)malloc(size3*sizeof(double));
        mergeandsortarray(size1, arr1, size2, arr2, arr3);
        printf("\nSorted Array 3, consisted of %d elements\n",size3);
        printarray(size3,arr3);
        
           
        
        
        
        getch();
        return 0;
    }
    
    //** main end **
    
    //-----------------------------------------------------

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    Never used DevCPP, but a search brought me to this post:

    Dev C++ Spacing Problem

    Quote Originally Posted by swoopy
    Go to the editor options by:
    Tools -> Editor Options

    Under the General tab:
    Check: Auto Indent
    Uncheck: Use Tab Character and Smart Tabs
    Look for the edit box called Tab Size and make the number your preferred indent size.

    This should allow you to use the Tab key. It will also autoindent whenever a brace is entered (the next line will be indented).

    Note: you can play with these settings to get the desired feel. Some may prefer the have Use Tab Character checked.
    Don't know if there's a way to reformat your existing code to the new indent rules. You might have to do it by hand. In most editors you can select many lines of code and use TAB to indent all of them at once, and shift-TAB to unindent them. If I had to fix it by hand I'd select chunks of code needing the same indent then shift-tab them to the beginning of line then tab them out again.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Good advice from all... but you might also want to consider getting an IDE/compiler that is still supported. DevC++ has been a dead horse for about 5 or 6 years now and the compiler that comes with it is superceded by about 3 updates.

    If you're working in plain C-99 you might consider Pelles C ... right up to date, 32 and 64 bit compilers, full set of Windows resource editors, Windows headers and libs and he best help file I've ever seen.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I second Pelles C. No tons of crap to wade through. Short learning curve, and Tater and I can answer your questions (probably), in detail. Also, it has it's own forum for any questions we can't answer.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I second Pelles C. No tons of crap to wade through. Short learning curve, and Tater and I can answer your questions (probably), in detail. Also, it has it's own forum for any questions we can't answer.
    That and the forum has special areas for user contributed code and addins to make it even more flexible.
    (In fact, you might recognize one of the contributing authors over there )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. indentation o indentation!
    By rogster001 in forum C++ Programming
    Replies: 18
    Last Post: 09-23-2009, 06:53 AM
  2. code indentation
    By bbeltwilson in forum C++ Programming
    Replies: 11
    Last Post: 12-30-2008, 11:17 AM
  3. Have I got the hang of indentation?
    By Caduceus in forum C++ Programming
    Replies: 12
    Last Post: 01-25-2008, 10:38 AM
  4. setting indentation in dev-c++
    By richdb in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-12-2006, 09:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21