By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,786 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

C Beautifier

P: 13
I would to attempt a simple code beautifier but I would like to know the right way to start this.

The process I would like to attempt is:
1. Start count out at zero.
2. Read in lines of original.c one by one.
3. For each line:
4. Remove all the white space (tabs and spaces) from the front of the line.
5. If the first non-white character of the line is } decrease count by one.
6. Insert at the front of each line count*2 number of space characters.
7. If the first non-white character of the line is { increase count by one.

The code I wrote is a not a good attempt so I would appreciate any help in fixing this code

Expand|Select|Wrap|Line Numbers
  1. int main(char string[])
  2. {
  3. const char sp = '.';
  4. const char cr = '*';
  5. const char tab = '$';
  6. const char rb = '{';
  7. const char br = '}';
  8. const char space = ' ';
  9.  
  10.  
  11. char ch;
  12.  
  13. int in = 0;
  14. int count = 0;
  15.  
  16. int inSpace = 0;
  17.  
  18. while( (ch = string[count]) == sp|| ch == cr|| ch == tab || ch == space )
  19. count++;
  20.  
  21.  
  22. while ( ch = string[count++] )
  23. {
  24.  if (ch == br)
  25.  {
  26.    count--; 
  27.  }
  28.  
  29. }
  30.  
  31. while ( ch = string[count++] )
  32. {
  33.       if ( ch = rb)
  34.       {
  35.            count++;
  36.       }    
  37. }
  38.  
  39. }
Nov 21 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.