I know I've posted this code a couple of times now so I feel really stupid asking again for help but the requirements for the challenge that I'm working on changed a little bit on me.
What I now need to do is take in a list of numbers, assuming it will be an even numbered list of numbers, and compute the cycle length of the pairs of numbers given. But when I accept the numbers at the command line, the program crashes. I know it's because of my inexperience with pointers and arrays of pointers.
Here is the link to the challenge that I'm working on.
Code:/* program overflows @ command line */ #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int *inci; //holds the incremental value of i int *origi; //hold the original value of i to increment int *num1, *num2; //numbers to be compared int count = 0; //count is the more permanent storage for counting cycle length int temp = 0; //temp is the temporary storage for testing greatest cycle length while(argc > 1) { int i = 1; *origi = atoi(argv[i]); *inci = atoi(argv[i]); *num1 = atoi(argv[i]); *num2 = atoi(argv[i+1]); while(*num1 <= *num2) { while(*num1 != 1) { if(*num1 % 2)//if i is odd { *num1 = (3 * (*num1))+1; ++temp; } else // assumes that i is even { *num1 = (*num1)/2; ++temp; } if(temp > count) //stores the largest temp number into count to be printed later { count = temp; temp = 0; } } *num1 = ++(*inci); argc -= 2; argv += 2; } printf("%d %d %d \n", *origi, *num2, count); } return 0; }