All Questions
Tagged with formatting c
276 questions
2
votes
1
answer
52
views
Line break after each preprocessor condition with clang-format
I would like to have clang-format insert a line break after each preprocessor condition after the operators.
For example:
#if ((CONDITION_A_SWITCH == ENABLED) || (CONDITION_A_SWITCH == ENABLED) || (...
1
vote
0
answers
57
views
Eclipse formatting for array initializer with long names
I'm using Eclipse 4.29.0 CDT (STM32CubeIDE) to write C code and have a curious behavior with the auto formatting feature. Arrays with numbers or short element names are formatted as expected (first ...
0
votes
2
answers
206
views
Reasoning behind Barr C Coding Standard: Why have white spaces around asterisk in pointer declaration? [closed]
The Barr C Coding Standard 2018 has the Rule 3.1e:
The pointer operators * and & shall be written with white space on
each side within declarations but otherwise without a space on the
operand ...
1
vote
1
answer
54
views
How do I split up multiple operations done on one line in C with Uncrustify?
In C, I want to split multiple operations done on one line to their own lines.
E.g.
int foo;
int bar;
foo = 123; bar = 456;
Should be changed to:
int foo;
int bar;
foo = 123;
bar = 456;
What ...
1
vote
1
answer
133
views
General text wrap program in C
I'm trying to make a general text wrap in C. Basically it should handle the text in the following way:
A maximum line length is determined
It must always wrap the text in the spaces, when it is ...
1
vote
1
answer
90
views
How can I print out blocked clients in color in the console using C
I am trying to print out all clients in different color. The ones that have not the status 'blocked' in normal white color, and those who have the status 'blocked' should be printed out in color red ...
0
votes
0
answers
82
views
printf("%d", x) alters value of %d when spaces are added to the formatted string? [duplicate]
Consider this very simple lines of code:
#include <stdio.h>
#include <stdlib.h>
typedef int board[8][8];
board * initBoard(void)
{
board * b = malloc(sizeof(board));
if (!b) { ...
1
vote
1
answer
518
views
Mimic linux xxd command in C
I have the problem mostly solved, I just can't get the last line to be formatted correctly with spaces. I am close, but I need another set of eyes on this
#include <stdio.h>
#include <stdlib....
3
votes
3
answers
208
views
How to use C/C++ format specifiers to achieve the same as "g" but with "1." instead of "1.0"
I'd like to print floats via printf as follows:
(1) right-align into a string of given width (here 8)
(2) show relevant decimal digits if possible, but no unneccesary trailing 0s after .
(3) also do ...
0
votes
0
answers
74
views
Print several lines inside one column in the terminal (with a c program)
I would like to format the output of the program according to column. When the text of a column is wider than the column, I would like it to be printed on several lines which would however stay in ...
1
vote
2
answers
38
views
Save the date of today in a string
I want to save the date of today in a string and have the following code with the following output:
Code:
#include <stdio.h>
#include <time.h>
int main()
{
time_t t = time(NULL);
...
0
votes
1
answer
1k
views
C/C++ How to format if conditions' single statement on the same line in VScode
If you don't use curly braces in C/C++ after declaring a condition, the body of the function becomes the next statement directly after; same thing for loops (while, for etc....).
I want the formatter ...
1
vote
1
answer
190
views
Better way to write a csv in C with many variables and digit specifiers?
I currently have something like 13+ variables and 500,000 datapoints I'm outputting to a csv file, and I might add more outputs later since the project is in its early stages. The last fprintf line is ...
0
votes
0
answers
240
views
"javascript.format.insertSpaceBeforeFunctionParenthesis" setting doesnt work for C code
Below are my vscode settings
"editor.formatOnPaste": true,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format....
0
votes
1
answer
135
views
How do I interpret ASCII values of characters of a string as chars in C?
I have a sequence of numbers representing ASCII values of alphabet characters [A,Z], [a,z] and " ". I can get in a char the ascii value of one of the values (i.e. char = 76), but when I try ...