Run time error??

gubbaraviteja

Right off the assembly line
Hello guyz,
I'm ravi and BTW in an attempt to solve a problem I encountered with the following error.
The problem is as follows:

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

Input:
1
2
88
42
99

Output:
1
2
88

My code to solve the above problem is as follows:
<code>
#include <stdio.h>
void main()
{
int n,flag=0;
do
{
scanf("%d",&n);
if(n==42) flag=1;
}while(flag==0);
}

</code>

But the judge says there is a runtime error..
can any one tell me where the error is??
but it perfectly executing in my command prompt with GCC compiler.
Please help me asap.
 

nims11

BIOS Terminator
use
Code:
instead of <..></..>

hmm a codechef question..
u need to print out the numbers inputted before 42 also. also to prevent runtym error, change void main to int main and return 0; at the end of main.
the code below should work.
Code:
#include <stdio.h>
int main()
{
int n=0;
while(1)
{
scanf("%d",&n);
if(n==42)
break;
printf("%d\n",n);
}
return 0;
}
all the best!!
 
OP
G

gubbaraviteja

Right off the assembly line
Hello nims,
thank u for the reply and the problem got solved when void main() is replaced as you said, but why there is runtime error if we use void main()?
Is there any concept, can anyone clear this doubt please.

waiting for the reply..:)
 
^^ please Google it up.

some links to get you started ::

[29] Newbie Questions / Answers *Updated!*, C++ FAQ
Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])
int main() vs. void main()

its best if you stick with standards. doing so will prevent such situations like yours from happening

see:: *www.ecma-international.org/publications/standards/Ecma-372.htm
 

Garbage

God of Mistakes...
C1X is the planned new standard for the C programming language. You might want to check it.
C1X - Wikipedia, the free encyclopedia
 
Top Bottom