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

LISP part V

Name: Anonymous 2008-03-08 8:38

LISP

Name: Anonymous 2008-04-04 11:14

>>408
$ cat sort.c
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort(uintmax_t *numbers, size_t length){
 uintmax_t temp[length];
 uintmax_t *arrays[2] = {numbers, temp};
 for(uint_fast8_t i = 0; i < sizeof(uintmax_t) * CHAR_BIT; ++i){
  for(size_t j = 0, start = 0, end = length - 1; j < length; ++j){
   if(!(arrays[i & 1][j] & 1 << i))
    arrays[i & 1 ^ 1][start++] = arrays[i & 1][j];
   if(arrays[i & 1][length - j - 1] & 1 << i)
    arrays[i & 1 ^ 1][end--] = arrays[i & 1][length - j - 1];
}}}

int main(int argc, char *argv[]){
 if(argc>1){
  size_t len=strlen(argv[1]);
  uintmax_t *array = calloc(len,sizeof(uintmax_t));
  for(size_t i=0;i<len;++i) array[i]=(uintmax_t)argv[1][i];
  sort(array,len);
  for(size_t i=0;i<len;++i) argv[1][i]=(char)array[i];
  puts(argv[1]);
 }
 return 0;
}
$ gcc -Wall -ansi -pedantic -std=c99 sort.c; ./a.out 5a7asfgadf34; rm a.out
sort.c: In function `sort':
sort.c:13: warning: suggest parentheses around arithmetic in operand of ^
sort.c:15: warning: suggest parentheses around arithmetic in operand of ^
3457aaadffgs
$


tl;dr you don't know C.

Newer Posts