Talk:C: Difference between revisions
(more) |
(done) |
||
Line 3: | Line 3: | ||
#include <stddef.h> |
#include <stddef.h> |
||
#include <ctype.h> |
#include <ctype.h> |
||
#include <string.h> |
|||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
#include <assert.h> |
|||
⚫ | |||
#define strize(X) strize_(X) |
|||
#define K62 62 |
#define K62 62 |
||
⚫ | |||
#define K3 4 |
#define K3 4 |
||
#define K3_ (K3-1) |
#define K3_ (K3-1) |
||
extern int main(int ac, const char *const *av) { |
extern int main(int ac, const char *const *av) { |
||
static char b[K62][ |
static char b[K62][101][K3]; |
||
char a[666]; |
char a[666]; |
||
int ln= 0; |
int ln= 0, k_= 7; |
||
size_t k; |
|||
if (ac>>1) k_= atoi(av[1]); |
|||
k= k_>=40? k_: k_+80u; |
|||
for (; fgets(a, sizeof a, stdin); ) { |
|||
size_t y, z= strlen(a); |
size_t y, z= strlen(a); |
||
char *s= a+z; |
char *s= a+z; |
||
for (; z && ( |
for (; z && (iscntrl(*(unsigned char *)--s)); --z, *s= 0); |
||
y= z? (z-1)/ |
y= z? (z-1)/k + 1: 1; |
||
z= z>=K3_? K3_ : z; /* !needed? */ |
z= z>=K3_? K3_ : z; /* !needed? */ |
||
Line 28: | Line 37: | ||
int lo= ln%K62, hi= ln/62; |
int lo= ln%K62, hi= ln/62; |
||
sprintf(b[lo][hi], "%-" K3 ".*s", z, a); |
sprintf(b[lo][hi], "%-" strize(K3) ".*s", z, a); |
||
} |
} |
||
} |
} |
||
ln= (ln-1)/K62 + 1; k= (ln-1)/2 + 1; fprintf(stderr, "\nln= %d k= %u\n", ln, k); |
|||
for (ln= 0-1; ++ln<K62; ) { b[ln][k][-1]= 0; puts(*b[ln]); } |
|||
puts(" @@@@@@@"); |
|||
for (ln= 0-1; ++ln<K62; ) puts(b[ln][k]); |
|||
return EXIT_SUCCESS; |
|||
} |
} |
||
Revision as of 12:31, 11 September 2022
#include <stddef.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> #define strize_(X) #X #define strize(X) strize_(X) #define K62 62 #define K3 4 #define K3_ (K3-1) extern int main(int ac, const char *const *av) { static char b[K62][101][K3]; char a[666]; int ln= 0, k_= 7; size_t k; if (ac>>1) k_= atoi(av[1]); k= k_>=40? k_: k_+80u; for (; fgets(a, sizeof a, stdin); ) { size_t y, z= strlen(a); char *s= a+z; for (; z && (iscntrl(*(unsigned char *)--s)); --z, *s= 0); y= z? (z-1)/k + 1: 1; z= z>=K3_? K3_ : z; /* !needed? */ for (++y; --y; ++ln, z= 0) { int lo= ln%K62, hi= ln/62; sprintf(b[lo][hi], "%-" strize(K3) ".*s", z, a); } } ln= (ln-1)/K62 + 1; k= (ln-1)/2 + 1; fprintf(stderr, "\nln= %d k= %u\n", ln, k); for (ln= 0-1; ++ln<K62; ) { b[ln][k][-1]= 0; puts(*b[ln]); } puts(" @@@@@@@"); for (ln= 0-1; ++ln<K62; ) puts(b[ln][k]); return EXIT_SUCCESS; }