Hello! I've got problem because my program tested by SPOJ gave that answer:
Your solution from 2004-10-30 21:27:39 to problem TEST, written in C, crashed with Runtime Error: NZEC.
There's my code:
#include <stdio.h>
void main()
{
int table[100000], index = 0, i = 0;
do scanf("%d", &table[index]);
while (table[index++]!=42);
for(i=0;i<index-1; i++)
printf("%d\n", table[i]);
}
I've complied it in Borland C++ 5.02 and there weren't any problems. Can you help me? Thanks
The system requires the so called "exit code" of a program to be zero, otherwise you get a Non Zero Exit Code (NZEC). The exit code of a C program is usually the value returned by the main function (or the argument of the function "exit").
So one solution is to change the type of "main" to "int main(void)" and add "return 0;" at the end of your program.
Another solution would be to add a line "exit(0);" at the end of your program and "#include at the beginning.
"2004-09-06 02:53:26 NZEC overrides ACC by Tomek Noinski There has been an important change: from now on, a program has to exit with exit code 0 to get AC. It will get Runtime Error: NZEC otherwise. We believe it's better this way. "
It's main intention is to tell, when a program in a language such as Python, Perl, Java, Pascal and other doesn't really finish successfully, but throws an exception or something similar. For interpreted-only languages, NZEC can also mean a parse error. Why does it also work for C? To keep it simple. Anyway, returning non-zero exit code is a convention for telling that something went wrong. And it's a feature of C, that if you don't explicitly specify the exit code, it is not specified what it would be. It changed in C++.
The C99 standard states that reaching the } that terminates main() returns 0.
ISO/IEC 9899:1999 Programming languages -- C Section 5.1.2.2.3 Program termination
A GCC specific solution to this problem could be to compile with "-std=c99", or link every submitted solution with something like the following translation unit:
Unless of course somebody explicitly returns or passes to exit() a value different from 0, which seems like a very unlikely scenario in this circle (in which case "-std=c99" seems like the better option).
DISCLAIMER: just want to lower the character count in size contest problems
But making sure the program returns 0 on that specific architecture and gcc version is a part of the challenge! If you want, you could try submitting as C++, but it would break some other possible "improvements"..