seq.c (1352B)
1 /* 2 * -f, --format: Use a printf style format 3 * -s, --separator: Use string to separate numbers 4 * -t, --terminiator: Use string to terminate sequence of numbers 5 * -w, --fixed-width: Equlize the widths of all numbers by padding with zeros as necessary. 6 */ 7 #include<stdio.h> 8 #include<stdlib.h> 9 10 int sequence(long f_num, int incr, int l_num) 11 { 12 long i; 13 if (f_num < l_num) { 14 for (i = f_num; i <= l_num; i = (i + incr)) { 15 printf("%ld\n", i); 16 } 17 } else if (l_num < f_num) { 18 for (i = l_num; i <= f_num; i = (i + incr)) { 19 printf("%ld\n", i); 20 } 21 } 22 23 return 0; 24 } 25 26 int main(const int argc, const char *argv[]) 27 { 28 printf("Number of arguments: %d\n", (argc - 1)); 29 long nums[argc - 1]; 30 int i, j; 31 32 //nums[0] = strtold(argv[j], NULL); 33 34 for (i = 1; i < argc; i++) { 35 j = 0; 36 printf("Beginning loop\n"); 37 nums[j] = strtol(argv[i], NULL, 10); 38 printf("argument %d: %ld\n", i, nums[j]); 39 printf("End loop\n\n"); 40 } 41 42 int format = 0, sep = 0, term = 0, fw = 0; 43 44 for (i = 0; i < argc; i++) { 45 printf("%d in array is: %ld\n", i, nums[i]); 46 } 47 48 sequence(nums[0], 1, nums[1]); 49 50 /* 51 if (argc == 3) { 52 sequence(nums[0], nums[1], nums[2]); 53 } else { 54 sequence(nums[0], 1, nums[1]); 55 } 56 */ 57 58 }