09-16-2007, 09:40 PM
I am taking an intro to C. Right now I am using slickedit as an IDE which I can access remotely on campus through the X11 client. It's fine but it really is much more full featured and complicated than what I need. At this point all we are doing is "hello world" kind of stuff and simple functions.
I have tried X code and have been able to get a program to build with no syntatic errors, but I am stuck as to how to use the debugger to ferret out a logic error somewhere. Specifically, I can't figure out how to use the "step into" as it seems to differ from what I have been doing with slickedit.
In slick edit, I can step into the function as it executes each individual line. But in Xcode it seems to jump ahead and I never see parts of my code in the GDB debugger screen.
Here is the code as it stands now:
#include
void printRows(int);
int binomial(int n,int r);
int factorial(int n);
int main(void){
int numRows = 0;
/* Ask for a positive integer and repeat if negative.*/
do{
printf("Enter a positive integer\n");
scanf("%d",&numRows);
if(numRows<0)
printf("Negative number entered!\nTry again.\n");
}while(numRows<0);
printf("\nThe Pascal's triangle to the %dth row:\n",numRows);
printRows(numRows);
printf("\n\n");
return(0);
}
/* Prints the Pascal's triangle from row 0 to row numRows. */
void printRows(int numRows){
int i, j;
/*for each row in the triangle*/
for(i=0; i < numRows; i++){
/*for each column in this row. (note that there are N+1 columns in
the Nth row.) */
for(j=0; j <= i; j++){
/* Each element in the triangle is the binomial coefficient
(row column) i.e. row choose column. */
printf("%d ", binomial(i,j));
}
printf("\n");
}
}
/*Calculate and return the binomial coefficient n to r (i.e. n choose r)*/
int binomial(int n, int r){
return factorial(n)/(factorial®*factorial(n-r));
}
/*Recursively calculate and return the value of factorial n*/
int factorial(int n) {
/* factorial of 0 or 1 is 1 by definition.*/
if(n <= 1)
return 1;
else
/* for all the other numbers, the factorial is the product of the
number and the factorial of the immediately preceding number. */
return n*factorial(n-1);
}
Let me make it clear that I am not cheating on homework. This problem was due earlier in the week and I have already turned it in. So I am just practicing with Xcode because I would rather use it. Here are some screenshots of what I am seeing, just before it stops.

and after it stops, you can see that step into is greyed out:

Do I have to be setting break points or something? I tried putting one at the end, but it didn't help. Any assistance would be appreciated
Craig
I have tried X code and have been able to get a program to build with no syntatic errors, but I am stuck as to how to use the debugger to ferret out a logic error somewhere. Specifically, I can't figure out how to use the "step into" as it seems to differ from what I have been doing with slickedit.
In slick edit, I can step into the function as it executes each individual line. But in Xcode it seems to jump ahead and I never see parts of my code in the GDB debugger screen.
Here is the code as it stands now:
#include
void printRows(int);
int binomial(int n,int r);
int factorial(int n);
int main(void){
int numRows = 0;
/* Ask for a positive integer and repeat if negative.*/
do{
printf("Enter a positive integer\n");
scanf("%d",&numRows);
if(numRows<0)
printf("Negative number entered!\nTry again.\n");
}while(numRows<0);
printf("\nThe Pascal's triangle to the %dth row:\n",numRows);
printRows(numRows);
printf("\n\n");
return(0);
}
/* Prints the Pascal's triangle from row 0 to row numRows. */
void printRows(int numRows){
int i, j;
/*for each row in the triangle*/
for(i=0; i < numRows; i++){
/*for each column in this row. (note that there are N+1 columns in
the Nth row.) */
for(j=0; j <= i; j++){
/* Each element in the triangle is the binomial coefficient
(row column) i.e. row choose column. */
printf("%d ", binomial(i,j));
}
printf("\n");
}
}
/*Calculate and return the binomial coefficient n to r (i.e. n choose r)*/
int binomial(int n, int r){
return factorial(n)/(factorial®*factorial(n-r));
}
/*Recursively calculate and return the value of factorial n*/
int factorial(int n) {
/* factorial of 0 or 1 is 1 by definition.*/
if(n <= 1)
return 1;
else
/* for all the other numbers, the factorial is the product of the
number and the factorial of the immediately preceding number. */
return n*factorial(n-1);
}
Let me make it clear that I am not cheating on homework. This problem was due earlier in the week and I have already turned it in. So I am just practicing with Xcode because I would rather use it. Here are some screenshots of what I am seeing, just before it stops.

and after it stops, you can see that step into is greyed out:

Do I have to be setting break points or something? I tried putting one at the end, but it didn't help. Any assistance would be appreciated
Craig