Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ANY OF U REDDY 2 CHALLENGE ME YET?

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-06-20 0:33

CARN

Name: !!YtwzkeoLMFQUgZv 2013-06-20 13:35

>>41

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

int main(void) {
  char buf[BUFSIZ] = {0};
  size_t n, i, j, k;
  struct { size_t size, pos; } *m;

  fread(buf, 1, BUFSIZ - 1, stdin);
  n = strlen(buf);
  for(i = j = 0; j < n;
      j += strcspn(buf + j, "\n") + 1, i++);
  assert(i && (m = malloc(sizeof *m * i)));
  for(j = 0; j < i; j++) {
    m[j].pos = (j > 0) ? m[j-1].pos + m[j-1].size + 1 : 0;
    m[j].size = strcspn(buf + m[j].pos, "\n");
  }
  for(j = n = 0; j < i; j++)
    n = (m[j].size > n) ? m[j].size : n;
  for(j = 0; j < n*i; j++) {
    k = j % i;
    if(k == 0 && j != 0) putchar('\n');
    if(m[k].size*i > j)
      putchar(buf[m[k].pos + j/i]);
    else
      putchar(' ');
  }
  putchar('\n');
  free(m);
  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List