I have another problem with command line arguments.
But this time I'm mostly convinced that it's how I've set it up.
This program takes two numbers from the command line. The first and presumably lesser number is determined to be either even or odd. If the first number is even it divides the number by 2 and if the number is odd the number is multiplied by 3 and 1 then added to it and increments a counter every time either one of these events happens until the value is 1. The smaller number is then incremented by 1 and the process starts over again until the smaller number is equal to the second presumably greater number.
This is the code that I have, it compiles OK, but I have a logical error some where causing a segmentation fault and I believe it's how I'm using the command line information (or not using it as the case maybe).
Can see where I messed up?
int main(int argc, char *argv)
char i, j;
origi = i; //hold the original value of *i
int temp; //temporarily hold the cycle length.
i = argv; //Because I know where input will be I wanted to get it directly from command line
j = argv;
if( argc > 3)
printf("too many arguments\n");
for(count = 0, temp = 0; i <= j; i++)
while(i != 1)
if(i % 2)//if i is odd
i = (3 * i)+1;
else // assumes that i is even
i = i/2;
if(temp > count) //stores the largest temp number into count to be printed later
count = temp;
temp = 0;
printf("%d %d %d\n", origi, j, count);