Archives: [soy / q / int / g / asg / raid / giga / sci / lars / arch] [meta]
Update 2026-12-06: New! We now provide real-time archives for all boards on 4chan.org and swedishwin.com. 4chan archive / Swinny archive
Update 2026-12-04: You can now download threads to your computer in .html or .7z format. Watch the guide
[6 / 1 / 1]

rate my C

No.7323 View View Original Report
Kind of new to C, made this half ass "range" implementation, its still missing safety checks, didn't add because it's getting late and i would have forgotten about it if i left it to tomorrow, just wanted to post this here. (C) #include <stdio.h> #include <stdlib.h> #include <stdint.h> int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s [START] STOP [STEP]\n", argv[0]); return 1; } int64_t Start = 0; int64_t Stop = atoi(argv[1]); //TO DO: USE SOMETHING BETTER THAN ATOI uint64_t Step = 1; if (argc == 3) { Start = atoi(argv[1]); Stop = atoi(argv[2]); Step = 1; } else if (argc == 4) { Start = atoi(argv[1]); Stop = atoi(argv[2]); Step = atoi(argv[3]); //CHECK IF ARGV3 IS POSITIVE! } else if (argc > 4) { fprintf(stderr, "Usage: %s [START] STOP [STEP]\n", argv[0]); return 1; } if (Start > Stop) //need to check other edge cases where Start/Stop/Step are very big/small { fputs("Start must not be larger than Stop.\n", stderr); return 1; } uint64_t Size = ( ( (Stop - Start) / Step) +1) * sizeof(int64_t); int64_t *arr = malloc(Size); if (!arr) { fputs("Memory allocation failed.\n", stderr); return 1; } uint64_t Stage = 0; for (int64_t i = Start; i < Stop; i += Step) { arr[Stage] = i; Stage++; } //Used for debugging, free to delete for (int64_t i = 0; i < Stop; i++) { printf("%li\n", arr[i]); } free(arr); arr = NULL; return 0; }