473,394 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C Beautifier

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
0 1123

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

Similar topics

0
by: Robert Freund | last post by:
I've been looking for a good and free code beautifier that runs on linux. About the only ones I found where Trita (www.trita.com), which costs money and only runs on windows. The other one was...
13
by: OvErboRed | last post by:
Hi, I'm wondering if anybody can point me to a good, free C++ formatter/beautifier. I'm looking for something that offers the level of control that the Unix/Linux 'indent' program provides, but for...
19
by: Diego Andres Alvarez Marin | last post by:
Hi all! Is there a linux tool that uses as input my ugly C/C++ code and outputs a pretty and nice formated source code? Regards, Diego
1
by: Sparhawk | last post by:
Hi, I want to integrate a code beautifier for C++ in the development process of my company. There are many beautifiers around which would meet our formatting requirements (SourceFormatX,...
6
by: Zhou Lei | last post by:
GNU Indent is a powerful beautifier for C, and I'm using astyle to do that for C++. But it's not perfect, anyone knows a free tool in Linux? Thanks.
4
by: groleo | last post by:
Hi. Do you know any good code beautifier for c++? I tried indent but it screws my code, and astyle seems to go by its own rules :)
2
by: Matt England | last post by:
I am looking for a C++ code beautifier/styler. Requirements and a list of potential choices follow. I'm looking for people's specific recommendations and reasons thereof per their specific...
4
by: Shug | last post by:
Hi, We need a C++ beautifier, and due to the specific requirements of some of our developers, it has to be very configurable. After trying some free ones, we now realise that we might need to...
18
by: Franz Steinhaeusler | last post by:
Hello, I did not find any reasonable pyhton source code beautifier program (preferable gui). Some would ask why? Program it immediatly good. (BTW: Would be a nice project, if I would have more...
2
by: sevak316 | last post by:
Searched the forum and didn't find any topics on this. Does anyone know where I can find a user friendly C beautifier. We are using Indent right now, but it doesnt have a friendly interface. If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.