Skip to content

Instantly share code, notes, and snippets.

@incognitojam
Created June 4, 2019 11:29
Show Gist options
  • Save incognitojam/fd31ce507911150d13a638690117cecf to your computer and use it in GitHub Desktop.
Save incognitojam/fd31ce507911150d13a638690117cecf to your computer and use it in GitHub Desktop.
simple loops in c
#include <stdio.h>
int main(int argc, char **argv)
{
int i, max;
// check at least one argument provided
if (argc < 2) {
printf("missing required argument max");
return -1;
}
// read max argument from args
sscanf(argv[1], "%d", &max);
// ensure that the max value is valid
if (max < 1) {
printf("expected type int for argument max");
return -2;
}
// print numbers in range [0, max)
for (i = 0; i < max; i++)
printf("%d\n", i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment