Created
June 4, 2019 11:29
-
-
Save incognitojam/fd31ce507911150d13a638690117cecf to your computer and use it in GitHub Desktop.
simple loops in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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