logo

utils

~/.local/bin tools and git-hooks

range.c (729B)


      1 // Copyright CC-BY-SA-4.0 2017- Haelwenn (lanodan) Monnier <contact@hacktivis.me>
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 char *IFS;
      7 int a, b;
      8 
      9 void usage(char *a0) { printf("usage: %s [ini <max>]\n", a0); }
     10 
     11 void range(int initial, int maximum)
     12 {
     13 	printf("%i", initial);
     14 	if(initial < maximum)
     15 	{
     16 		for(initial++; initial <= maximum; initial++)
     17 			printf("%s%i", IFS, initial);
     18 	}
     19 	else if(initial > maximum)
     20 	{
     21 		for(initial--; initial >= maximum; initial--)
     22 			printf("%s%i", IFS, initial);
     23 	}
     24 }
     25 
     26 int main(int argc, char *argv[])
     27 {
     28 	if(!(IFS = getenv("IFS")))
     29 	{
     30 		IFS = " ";
     31 	}
     32 
     33 	if(argc == 2)
     34 	{
     35 		range(0, atoi(argv[1]));
     36 	}
     37 	else if(argc == 3)
     38 	{
     39 		range(atoi(argv[1]), atoi(argv[2]));
     40 	}
     41 	else
     42 	{
     43 		usage(argv[0]);
     44 	}
     45 }