Questions tagged [formatting]
For programs that are concerned with producing meaningful or clearer output. A typical example would be the transformation of a decimal into a particular currency format with the correct number of decimal places. (Note that code layout is always in scope for answers, so this tag is not used to indicate perceived issues with that).
587 questions
6
votes
3
answers
270
views
ASCII-based Lightweight Browser in Python with Clippy-Style Helper (Updated)
This question used to contain a mistake in the code, so I had to debug and reformat it. This is the correct version.
Why I made it
A friend and I wanted to make a lightweight browser, since our ...
5
votes
5
answers
1k
views
c++ format_to verbosity
I was concatenating a lot of strings lately, usually the results of std::format:
...
4
votes
3
answers
1k
views
A function to convert numbers from scientific notation to plain decimal
When PHP converts a number to string (for printing it out, for example), sometimes it may convert it to scientific notation out of nowhere (0.000021 for example). Or the number can be already in a ...
6
votes
2
answers
386
views
To markup a C++ std::ostream and delegate formatting of markuped text
I want to create a system that marks up text with tags inserted into a stream. Each tag frames a part of the text, creating a tree-like structure, just as in classic markup languages (HTML, XML...). I ...
3
votes
1
answer
113
views
Multiline string concatenation
Problem Description
Printing the result of adding two numpy arrays together is very ugly.
Here we will use these numpy arrays as an example:
...
4
votes
2
answers
169
views
Python (API requests)
I'm somewhat new to python and I'm creating a script that requests to a certain API and then uses the response to populate a ...
0
votes
1
answer
276
views
code to format text input to 2 decimal places before computation
I have this piece of code that checks the input of a text box before I compute for my main logic. This looks like it should be refactored but I'm currently stumped how to do so. The only thing that ...
1
vote
2
answers
169
views
Optimizing - formatting a person's name
I need to take a user's name and format it 'lastName, firstName middleName'. If firstName and middleName are not present then the comma should not be included with lastName. Below is what I came up ...
1
vote
1
answer
273
views
Short Text Pre-processing
For educational purpose I am preprocessing multiple short texts containing the description of the symptoms of cars fault.
The text is written by humans and is rich in misspelling, capital letters and ...
2
votes
1
answer
151
views
Multithreaded segmented Sieve of Eratosthenes
I am fairly new to Rust and thought a good way to practice would be to write a multithreaded segmented Sieve of Eratosthenes. It performs ok (searches ten-billion numbers in about 11 seconds on my ...
3
votes
2
answers
291
views
K&R Exercise 5-11. Modify the "detab" - to accept a list of tab stops as arguments
So far I have reached chapter 5 of the K&R Book, Edition 2 from which I have been learning C. I spent a few days thinking of a solution to this program. I wrote two or three versions of the same ...
3
votes
2
answers
325
views
K&R Exercise 4-6. Add commands for handling variables
For the following exercise (Chapter 4, Ex-4.6) of the Book (K&R 2nd Edition):
Exercise 4-6. Add commands for handling variables. (It's easy to
provide twenty-six variables with single-letter ...
7
votes
3
answers
1k
views
K&R Exercise 1-19. "detab" program that replaces tabs with the appropriate number of blanks
I am trying to do a few exercises from the K&R book from the first chapter - exercise 1-19. I have to write a program "detab" which replaces tabs in the input with the proper number of ...
5
votes
1
answer
992
views
IFormatProvider for double to engineering notation
A c# format provider that formats a double into a string using engineering notation rules.
If the value is outside of the defined notation symbols it will default ...
3
votes
2
answers
122
views
Re-designing c-style Input Output
Re - designing c-style input output [ btw I use printf() and scanf() in the core ]
Reasons for redesigning it :-
Needs 2 functions for input output [ namely ...
3
votes
1
answer
717
views
LeetCode 68. Text Justification
I am trying out Leetcode problem 68 and I need your help to asses the code. I am pretty new to this.
Given an array of strings words and a width ...
1
vote
1
answer
2k
views
Integer array to string
This function creates takes an int * buffer and creates a neatly formatted string (useful for printing the contents of an array).
Is the code easy to follow?
Is it ...
3
votes
1
answer
1k
views
Python function to output a string that is justified to the right
I just solved this exercise from Think Python, 2nd edition:
Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
8
votes
1
answer
182
views
Converting a number to a string with a maximum of 3 numerals plus SI unit
I wrote a function that receives a number as an argument and returns a number (technically, a string) with a maximum of 3 numerals, no matter if there's a decimal separator or not, plus the adequate ...
2
votes
4
answers
1k
views
Formatted output of a phone number from an array of int
I wrote a function that takes an array of 10 integers (from 0 to 9) that returns a string of those numbers as a phone number.
Example:
...
19
votes
4
answers
4k
views
Minimal `printf` for integer types in x86 assembly
I'm writing a minimal C runtime targeting an old 32-bit Windows XP machine as a personal project. The C runtime provided by compilers is quite bloated. I wouldn't mind some library bloats up to ...
4
votes
0
answers
86
views
formatting flattened string into JSON-like object in C++, part 2
I have reworked the code from my previous (linked) post.
For reference:
I have a string which contains JSON-like object flattened (stringify()ed).
I need to JSON-...
-2
votes
2
answers
158
views
Write conditional expression better [closed]
I have the following code
function x () {
return a ? (b ? 'result2' : 'result1') : 'result1';
}
Is there a better way to combine these two conditions into one?...
0
votes
2
answers
135
views
Is there a neater, more elegant way to format this output?
I have this code that writes the initial configuration of a simulator I'm writing to stdout. args is an instance of type ...
4
votes
1
answer
600
views
Gear Shift Indicator using Hall Effect Sensors & 8x8 LED Display
I wired up a Gear Shift Indicator for my dad's car to display what gear it is currently in, and showing changes with animations (sliding up and down as appropriate, with a few bonus ones for fun at ...