If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Program crashing when reading text from files

I'm writing a code obfuscator in C. Debugger shows no errors in the code, but the program crashes after compiling-- what can be the problem here? I'm guessing it has something to do with while loops or reading data from files, but I'm not sure how to fix it. Thanks in advance.

Re: Program crashing when reading text from files

Debugger shows no errors in the code

The debugger is there to help you debug your code - it doesn't show compile errors. The compiler will show these - or the linker will show linking errors.

If the program compiles and links without error then the problem is a logic error within the program. For that you need to use the debugger to trace through the code to see where the execution deviates from that expected from your design.

but the program crashes after compiling

What error is shown?

What os/compiler are you using?

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
C, C++ Compiler: Microsoft VS2015

Re: Program crashing when reading text from files

Originally Posted by moedea

Debugger shows no errors in the code, but the program crashes after compiling

You have misconceptions as to what the compiler and debugger do. If you had a program that is supposed to add two numbers, but instead by mistake you coded it to subtract two numbers, is that a valid 'C' program? It is valid if it compiles OK, but of course it doesn't do what you expected it to do, so you debug the program.

All the compiler does is to confirm that the code is syntactically correct and if correct, creates an intermediate file called object code. The compiler does not prove that the program will work correctly. The linker program then takes the object code and creates the final executable, which you then run to confirm that the program is coded correctly.

When you run the executable, you are responsible for fixing any runtime bugs. To do that, you debug your program using the debugger. The bottom line is that just because a program compiles OK doesn't mean it will run OK.

what can be the problem here? I'm guessing

Don't guess -- run the program using the debugger and debug the code. That is what everyone here would do to address your problem.

but I'm not sure how to fix it.

But didn't you write the code? If you did, then you must have had a plan (as 2kaud mentioned) to allow you to write such code. So debug the code and see where your plan falls apart. Once you see where this is, then you fix the code (or write the code differently, depending on your findings).

Re: Program crashing when reading text from files

In addition, you should ALWAYS check that a pointer is not NULL before using it.
Your getOtherCharacters() function can return NULL which will cause your program to crash when you attempt to write the data to the stream.