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).

Filter by
Sorted by
Tagged with
3 votes
2 answers
94 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 ...
2 votes
1 answer
91 views

K&R Exercise 1.22 - "fold" long input lines

Until recently, I decided to go back to Chapter 1 of the K&R Book, Edition 2, to try to "improve" the code I've already done. I have also made some changes since I was limited to just ...
2 votes
2 answers
105 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 ...
8 votes
3 answers
676 views

K&R Exercise 3-3. Expands shorthand notations (e.g., a-z to abc..xyz, 0-9 to 012..789)

I have been learning C with K&R Book 2nd Ed. So far I have completed quite a few exercises. For the following exercise (Chapter 3, Ex-3.3): Exercise 3-3. Write a function expand(s1, s2) that ...
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 ...
3 votes
2 answers
453 views

Printing a C++ struct

Critique? ...
  • 1,394
4 votes
1 answer
346 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 ...
  • 185
5 votes
2 answers
2k views

C++ I wrote a simple and fast formatting library for strings

C++ FString A quick C++ formatting library I was working on a logging library, and needed some way to format strings quickly, simple and clean, so I wrote this library. This library is not the best in ...
3 votes
2 answers
73 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 ...
  • 133
0 votes
2 answers
112 views

12 hour to 24 hour time conversion

doing hackerrank challenges and been learning python3 for a month now, made this code to convert and return 12 hour to 24 hour time format in one of the challenges ...
3 votes
1 answer
131 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
34 views

Rust program to print citations in Chicago author-date style

I have written a Rust program that lets you input a citation's metadata in a Bibtex-like format and generates a bibliography entry formatted in Markdown that conforms (more or less) to the Chicago ...
  • 207
0 votes
1 answer
70 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 ...
  • 155
4 votes
1 answer
158 views

Parse floats to a custom numeric format string

I'm working to implement a custom string format. These are the float values to convert into a string: ...
  • 43
3 votes
1 answer
342 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 ...
0 votes
1 answer
57 views

custom button class for android game engine

I'm a self-taught programmer and I haven't really followed industry-standard coding classes. I'm currently coding my own game engine for android, though and I was wondering if my coding style could ...
  • 3
8 votes
1 answer
90 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
1 answer
92 views

Encode non-negative integer to a string of ascii letters and digits

I want to encode a non-negative integer to ASCII letters and digits. I wrote below code for that, that works, but which I assume too immature to use in production. ...
2 votes
4 answers
222 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: ...
3 votes
1 answer
568 views

Format an integer with space as thousand separator

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
19 votes
4 answers
2k 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 ...
  • 421
1 vote
2 answers
356 views

Create an ASCII table from CSV

The following code convert csv to ascii table. ...
4 votes
0 answers
38 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
1 answer
82 views

formatting flattened string into JSON-like object in C++

I have a string which contains JSON-like object flattened (stringify()ed). I need to JSON-ify it back. It's a custom format, so I wrote function to JSON-ify the ...
-2 votes
2 answers
127 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?...
3 votes
2 answers
457 views

Simple string manipulation in C (for small microcontrollers)

Although I have long experience of other languages, I've not used C until playing around with microcontrollers using the Arduino IDE. I'm a bit uncomfortable with my use of pointers in conjunction ...
0 votes
2 answers
98 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 ...
  • 103
2 votes
1 answer
85 views

Beginner Q: Is there a cleaner way to group a list in JS?

I'm looking to highlight some words on a webpage, I've grouped them now, but changed the css and html slightly and this seems to have broken it. For context, looking to add a list of words in JS which ...
4 votes
1 answer
228 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 ...
1 vote
2 answers
53 views

Colour message prettifier in Bash

Features: messages formatted with clear borders errors sent to stderr colour handling colours can be included in other strings echoed to the screen without having ...
  • 229
-1 votes
2 answers
235 views

DiscountManager class in C#

I built a class in C#, DiscountManager, which is responsible for calculating a customer discount based on years of loyalty. I want to refactor it and am seeking any ...
3 votes
0 answers
121 views

Use formats phone numbers into XXX-XXX-XXX

I created an input that accepts and formats phone numbers into XXX-XXX-XXX. The user should be able to type numbers and the dashes should insert themselves automatically. Example #1: The user types 1 ...
  • 131
-1 votes
1 answer
157 views

Better way to format a query string in Java

description I'm using influxDB, I need use Java to generate a query command. The TestingTag struct maybe missing 0-3 fields. code: ...
7 votes
2 answers
302 views

Word wrap with file input & ouput

As this is a very basic word wrap program, it has at least the following 3 limitations :- The file should have a terminating newline. The column number at which the lines are to be wrapped must be ...
6 votes
1 answer
472 views

Python function to print a two-column table from a dictionary

I'm currently learning Python for a masters and am trying to improve the best I can, as I'll need to know how to code in my future career. I currently have a function that builds a table from a ...
4 votes
1 answer
92 views

How to make my code shorter. This Code formats Credit card number. Vanilla JS

How to make my script shorter and better? This code allows only digits, auto-format card number like this XXXX XXXX XXXX XXXX. if user hits delete or backspace to delete space in between digits, ...
  • 41
1 vote
1 answer
247 views

Read and display JSON results from Google Books API

I’m working with the Google Books API and I’m not so sure about the way I’m going to get the search data and return it to the user. I will describe the path here and I would like to know if you would ...
  • 369
0 votes
1 answer
50 views

Very unorthodox placement of if-else clauses in C for handling special cases [closed]

I've encountered a situation with an if-else clause. Specifically, the positive case has only 1 expression, whereas the negative case is a sequence of statements wrapped in braces. Like this: ...
  • 278
1 vote
1 answer
89 views

Format multiple dates to look good in text, using functional approach

I had a piece of code that solved really simple problem - it formated two dates to look better on a webpage. It looked like this: ...
  • 111
2 votes
3 answers
167 views

HTML/JavaScript temperature converter with rounding

I am looking to improve the performance of my code through best practices and cleaner code. My goal here is just to perform a conversion whenever there is a keyup. But I noticed that my code looks ...
  • 369
1 vote
1 answer
82 views

Car price calculator

Im writing this simple program for school and using NumberFormat on all the variables seems very repetitive (Note that we were asked to use the NumberFormat method)....
4 votes
2 answers
346 views

Tic-tac-toe in python with OOP

I'm a beginner to intermediate in programming, and created a Tic-tac-toe game in python. I plan to add an AI player and a GUI using pygame. Any improvements I could make to the code, especially with ...
  • 41
1 vote
0 answers
30 views

Powershell Refolder by Filename Before Delim

I'm pretty new to Powershell but have been using it more and more to automate tasks at work. Now I'm reaching out for some help. I typically use the scripts I write in a way where I copy and paste the ...
1 vote
1 answer
32 views

Is there a cleaner/better way to write this Contact Manager in React?

I am learning React by doing a Contact Manager, I am trying to write this code more efficiently. Any ideas...good practise, component splitting, formatting tips are accepted too. Thanks in advance P.S....
  • 13
0 votes
1 answer
148 views

Markdown table strings to two dimensional array converter implementation in C#

I am attempting to implement a converter which can convert List<string> type markdown table into two dimensional array ...
  • 3,596
1 vote
0 answers
26 views

Does Oracle have a mistake in their documentation regarding switch case formatting? [closed]

Here is a reference to how switch statements should be formatted (I've never seen this used at the two companies I've worked at): And a contradictory one, which I am partial to (and is IntelliJ IDEA ...
  • 131
2 votes
1 answer
404 views

Two Dimensional Array to Markdown Table Converter Implementation in C#

I am attempting to implement a converter which can convert two dimensional array (such as string[,]) into markdown table. The experimental implementation The ...
  • 3,596
2 votes
3 answers
147 views

Convert string format python

I want to fix number of digits after '.' in digit represented by string. Is there better solution than mine? My code ...
  • 125
0 votes
1 answer
161 views

JavaScript date format string to php date format string convert

Please find the following scenario, I've dynamic JS date format string from API but I am looking for the best way to convert the format that accepts in PHP date format. For now, I wrote it my own way ...
  • 1
13 votes
3 answers
1k views

Logger module in C

I wrote a logger module in C, that is essentially a printf wrapper + some additional color coding: I'd like get feedback how I can improve performance and also use better coding style. Right now, I ...
  • 795

1
2 3 4 5
12