RegNo starts at 1 because it needs to hold the contents of the next list. For example
UID RegNo
123 2005
124 2006
125 2007
Taking 5 off of the max for i will surely make it overshoot even more.
That doesn't make any sense, I don't think you understand arrays correctly.
I believe my original assumption was wrong, the index into words[] is not what is going out of bounds, I would say it is the indexes into UID and RegNo.
Suppose studentlength=4;
You now have UID[4] and RegNo[4].
They each index at
[0]
[1]
[2]
[3]
You start UID at [1], skipping [0]
And you start RegNo at [2] skipping both [0] and [1].
The indexes you skiped will not got populated with data.
Set a break point before the loop and put the variables into your watch window and step through all the code watching the values change as you go.