I strongly suggest reading a good C programming book (in 2020, Modern C).
It will be much faster than asking questions here. Don't forget to also read the documentation of your C compiler (perhaps GCC), your build automation tool (e.g. GNU make or ninja), and debugger (perhaps GDB). If you code on and for Linux, read also Advanced Linux Programming and syscalls(2), and the documentation of GNU glibc (or of musl-libc, if you use it).
Hovever, the program arguments is given as a null terminated array of strings to the main function, which is usually declared as
int main (int argc, char**argv) { /*...*/ }
if you run your program with ./hanoistower 3
and if your hanoistower.c
is your source code (which you need to compile with debugging and warning enabled, i.e. gcc -Wall -g hanoistower.c -o hanoistower
on Linux) then you have one extra argument, so
argc == 2
argv[0]
is the "./hanoistower"
string
argv[1]
is the "2"
string (use atoi
to convert it to an int
)
argv[2]
is NULL
Please, please learn to use the debugger (gdb
on Linux).