C language is unchecked, this means that as you access arrays, it don't check that you are in the array. Said otherwise, as long as you are in your memory space, you can do anything.
char line[128];
processed_fp = fopen("processed.txt","r");
while(fgets(line,256,processed_fp))
This is perfectly legal in C but very dangerous as any line longueur than 127 will trash memory after the space allocated to
line
. It start to matter is space after
line
is in use, because the variables after
line
are suddenly changing value without reason.
Your error message is when the OS detect that you are about to write in a memory space that is not yours.
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.
The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.