When you do
int k[j] = ...
you're actually declaring a new
int array, also named
And you're declaring it with a variable size (
j), which you cannot do in 'C', therefore the error thrown by
What you were probably trying to do there was accesing one location in the array, so as to store some value in there. That you do without prepending the
k[j] = ...
your first two lines of code are:
int k[n - 1];
there you're declaring two variables, but initializing none. I.e.: they don't have any values inside yet.
So, when you tell the compiler to allocate
n - 1 contiguous chunks of memory, each of size
int, and reference them as
k, your program failes to compile because the compiler doesn't know yet how much
'C' is pretty literal, and gets compiled on a "line-by-line" fashion. When you're about to allocate memory for a given variable, the compiler needs to know in advance how much memory will such variable utilize.
It's not enough for the compiler "the promise" that such variable will exist. Once, and only once, through the variable's lifetime, will you allocate memory for it. So, in this case, the size of the array needs to be know by the time you're declaring it (allocating memory for it).
If you need to dinamically allocate memory (i.e.: allocate memory at runtime, based on values calculated once the program has already started running) you need to follow another strategy, which you'll learn eventually through the course. But you shouldn't bother so far, since it gets a little more complicated, and you should get confident and become acquainted with a few basic concepts first.
vigenere, fixed-size arrays should do just fine. So, you should just estimate a maximum fixed size your array should have, and define it as such.