简体   繁体   中英

Eclipse CDT auto format C program

When I write C program code like this:

if ((input = fopen("input.txt", "r")) == NULL)

After use auto format ctrl+shift+F, the code turns into below, with "an extra space" after keyword NULL:

if ((input = fopen("input.txt", "r")) == NULL )

Would someone please help to figure out a solution? Thanks!

This issue is not related to Formatter -> Edit -> White space -> check "Before closing parenthesis". This extra space was added only after keyword NULL. Suppose I write:

if ((input = fopen("input.txt", "r")) == 0)

There will be no extra space added after 0, even if I use auto format ctrl+shift+F.

This can be adjuster in the formatter that you are using in Eclipse:

  1. Go to Windows -> Preferences -> C/C++ -> Code Style -> Formatter.

  2. Click on Edit.

  3. Click on "White Space" tab.

  4. Go to Control Statements -> 'if else'

  5. Uncheck "Before closing parenthesis"

在此处输入图片说明

So if i right you want to modify the settings of the formatter of eclipse, so you just go to

Window > preferences

and in the left panel find the:

C/C++>>Code Style>>Formatter

Now you click to edit the profile.

Go to the tab White spaces and find the Control statement >> 'if else' , now only modify the checkBoxes and you can redefine that as you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM