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

How to do this in Sepples?

Name: Anonymous 2011-08-14 12:58

iHaskal:
Data.Ix> range ((0,0), (3,4))
[(0,0),(0,1),(0,2),(0,3),(0,4),(1,0),(1,1),(1,2),(1,3),(1,4),(2,0),(2,1),(2,2),(2,3),(2,4),(3,0),(3,1),(3,2),(3,3),(3,4)]

Name: Anonymous 2011-08-14 15:38

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

int main(int argc, char **argv)
{
    int first[2], last[2];
    int i, j;

    if (argc < 5) goto error;
    first[0] = atoi(argv[1]);
    first[1] = atoi(argv[2]);
    last[0] = atoi(argv[3]);
    last[1] = atoi(argv[4]);
    if (first[0] > last[0]) goto error;
    if (first[1] > last[1]) goto error;
    goto run;

error:
    printf("%s: Error\n", argv[0]);
    return EXIT_FAILURE;

run:
    printf("[");
    for (i = first[0]; i <= last[0]; i++) {
        for (j = first[1]; j <= last[1]; j++) {
            printf("(%i,%i)%s", i, j, i < last[0] || j < last[1] ? "," : "");
        }
    }
    printf("]\n");
    return EXIT_SUCCESS;
}


Remember the C paradigm: if you need to malloc something print it to output instead.

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