Strike
10-13-2000, 03:04 PM
Okay, find where I went wrong with this, it's segfaulting on me (as far as I can tell, I calloc()ed the right amount and am not running past the end of the array, but then again, I'm used to C++ dynamic memory management). I was going to debug this myself, but DDD is taking forever to download and I'm not handy enough with gdb by itself to work with it ... *sigh*
Right now it's just (supposed to be) reading the command-line arguments into my integer array that I creatively named array and printing them (but that's just to test and make sure I'm referencing the indices right):
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int *array;
int i;
if (argc < 3) {
printf("Usage: euclid-gcd n1 n2 [n3 [n4 ... ]]]]\n");
exit(1);
}
array = (int *)calloc((argc-1), sizeof(int));
for (i=0; i<(argc-1); i++) {
array[i] = atoi(argv[i-1]);
printf("i = %d, array[i] = %d", i, array[i]); /* Diagnostics */
}
return 0;
}
This is not the code for the whole program, because I have other functions I will perform on that array once it is read in correctly, but this is what is giving me the error. TIA
Right now it's just (supposed to be) reading the command-line arguments into my integer array that I creatively named array and printing them (but that's just to test and make sure I'm referencing the indices right):
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int *array;
int i;
if (argc < 3) {
printf("Usage: euclid-gcd n1 n2 [n3 [n4 ... ]]]]\n");
exit(1);
}
array = (int *)calloc((argc-1), sizeof(int));
for (i=0; i<(argc-1); i++) {
array[i] = atoi(argv[i-1]);
printf("i = %d, array[i] = %d", i, array[i]); /* Diagnostics */
}
return 0;
}
This is not the code for the whole program, because I have other functions I will perform on that array once it is read in correctly, but this is what is giving me the error. TIA