Now, I make a little modification. I add a single line ( char array1[K]; ) within the function body.Basically I activate the deactivated line above so the code looks like
I wonder you were able to compile your code at all.
You can't declare an array with a non-const size (line 5 - char line[K];). In such a case the size of the array is not known to the compiler during compilation-time so it should print an error message and refuse to build your program.
The function is a much more complicated version of this one. I had to cut it down to as small as possible, but still contain the main idea, so I can track down the problem and post it here as well.
Good approach you propose, and neat, and it would work beautifully if the actual problem was as in the code.
BUT as this is part of a bigger problem I actually do need a couple of arrays of length K to use in the code, and compare with each other, at the same time.
You can't declare an array with a non-const size (line 5 - char line[K];). In such a case the size of the array is not known to the compiler during compilation-time so it should print an error message and refuse to build your program.
GCC will let you do this but for what reason I do not know.