Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created April 30, 2010 13:08
Show Gist options
  • Select an option

  • Save KristianLyng/385164 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/385164 to your computer and use it in GitHub Desktop.
/*
* This code executes on most/many new 64-bit x86 GNU/Linux platforms.
* Needs minor alterations for other platforms. Likely to explode.
*
* Usage: gcc sort2.c; ./a.out; (enter some lines and end with EOF/^d)
*
* Relevant functions:
* void qsort(void *base, size_t nmemb, size_t size,
* int(*compar)(const void *, const void *));
* Sorts ``base'' which is ``nmemb'' elements of size ``size'', using
* ``compar'' to sort each element.
*
* char *gets(char *s);
* Fetches one line from stdio an saves it in ``s'' (UNSAFE!), returns
* ``s'' on success or NULL on failure or EOF.
*
* int puts(const char *s);
* Prints the string ``s'' to stdout and returns non-negative on success.
*
*/
strcmp();
main(x){
int *z[999],i;
while(gets(i++*20+z));
x=qsort(z,--i,160,strcmp);
while(puts(x+z)&&z[x+=20]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment