Align columns/C: Difference between revisions

m
Fixed syntax highlighting.
(replaced with clean method)
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 1:
{{collection|Column Aligner}}
 
<langsyntaxhighlight lang="c">#include <stdio.h>
 
const char *str =
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$\n"
"are$delineated$by$a$single$'dollar'$character,$write$a$program\n"
Line 11:
"justified,$right$justified,$or$center$justified$within$its$column.";
 
void align(const char *in, char alignment)
{
int col, i, l, r;
int w[1024] = {0};
const char *s = in;
 
for (s = in, i = col = 0; s[i]; s += i + 1) {
Line 22:
if (i > w[col]) w[col] = i;
 
if (col++ >= 1024) abort(); /* artificalartificial limit */
 
if (s[i] == '\n') col = 0;
Line 56:
puts("\n---- center ----"); align(str, 'c');
return 0;
}</langsyntaxhighlight>
9,479

edits