towers of hanoi - what is wrong with this code?

Helo !

I'm trying to write a program, that solves the logical game "towers of hanoi" for n.
If you newer heard of it, heres the game's description from wikipedia:

The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of three pegs, and a number of disks of different sizes which can slide onto any peg. The puzzle starts with the disks neatly stacked in order of size on one peg, the smallest at the top, thus making a conical shape.

The objective of the game is to move the entire stack to another peg, obeying the following rules:

* Only one disk may be moved at a time.
* Each move consists of taking the upper disk from one of the pegs and sliding it onto another peg, on top of the other disks that may already be present on that peg.
* No disk may be placed on top of a smaller disk.

The problem with my program is: it DOES solve the problem IF there are 1-3 disks, but if the is 4, or more, it simply never ends.
Here's the code:

Code:

#include <stdio.h>
int a[101],b[101]={0},c[101]={0};
int main (void)
{
int i,*ki,*se,*ce;
scanf("%d",&i); /*how many disks should be*/
a[i]=0;
ki=&a[0];
se=&b[0];
ce=&c[0];
while (i-1 >= 0) /*this is the part where the program puts the "disks" on the first "peg"*/
{
a[i-1]=i;
i--;
}
hanoi(ki,se,ce);
while (c[i] != 0) /*the program writes out the contents of the third peg, represented as the "c" array*/
{
printf("%d ",c[i]);
i++;
}
return(0);
}
hanoi(ki,se,ce)
int *ki,*se,*ce;
{
int *swap,i;
beginning:
i=0;
while(*(ki+i) != 0)
i++;
if (i == 1) /*if theres only one disk, just put it on the right peg*/
{
put(ki,ce);
return(0);
}
if (i > 1) /*if there are more than one disks, use recursion: put all the disks except the last one on the "second" peg*/
hanoi((ki+1),ce,se);
put(ki,ce); /*and after that, put that last one on the right peg*/
swap=ki;
ki=se;
se=swap;
goto beginning;
}
put(from,to)
int *from,*to;
{
int i=0,j=0;
while(*(from+(i+1)) != 0)
i++;
while(*(to+j) != 0)
j++;
*(to+j)=*(from+i);
*(to+j+1)=*(from+i)=0;
}

In my program, three global integer arrays (a,b and c) represent the three pegs, and the disks are represented as integers. The smaller the integer is, the bigger disk it represent. The smallest integer (and biggest disk) is 1.
In the beginning, all the "disks" are in the "a" array, from 1 to n (depending on how many disks you want: the program asks you this in the beginning). The end of the three arrays are represented by a "0" after the last integer (this way it is easy to measure how "tall" the peg is).
The program uses a recursive function to solve this problem.

Have you determined how much stack space your recursive functions use? If you're using some ancient compiler, the default stack space is around a couple of KB, so you could easily blow that away if you're not careful.

Also, use more braces to indicate the grouping of statements. You don't have to restrict yourself to where they are compulsory, and it will save you grief in the long run.
Also, 1 space per indent isn't enough IMO to distinguish scope levels.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens