Why do I get an assertion failure?

My guess is that the file is failing to open, and you’re still passing it to fgets. Your if(rd==NULL) doesn’t stop execution of the fgets if it’s null, it just prints out a message and continues with execution. Some very basic errorr handling:

What is the use of “assert” in Python?

The assert statement exists in almost every programming language. It helps detect problems early in your program, where the cause is clear, rather than later when some other operation fails. When you do… … you’re telling the program to test that condition, and immediately trigger an error if the condition is false. In Python, it’s … Read more