Skip to content

Instantly share code, notes, and snippets.

Last active December 25, 2015 01:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A simple example that reads integer coordinates in the form x,y into a scv_vector and prints them in lexicographical order.
#include <stdlib.h>
#include <stdio.h>
#include "scv.h"
struct point {
int x;
int y;
int point_compare(const struct point *lhs, const struct point *rhs)
if (lhs->x == rhs->x) {
return lhs->y - rhs->y;
return lhs->x - rhs->x;
int main(void)
struct scv_vector *v;
struct point p;
size_t i;
/* create a scv_vector of points, reserving space for 10 */
v = scv_new(sizeof p, 10);
/* read coordinates into p and append to v */
while (scanf("%d,%d", &p.x, &p.y) == 2) {
scv_push_back(v, &p);
/* sort points in v */
qsort(scv_data(v), scv_size(v), scv_objsize(v), point_compare);
/* print points */
for (i = 0; i < scv_size(v); ++i) {
struct point *pp = scv_at(v, i);
printf("%d,%d\n", pp->x, pp->y);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment