changeset 89:90428161fc61

Prevent divide by zero error
author Thinker K.F. Li <thinker@branda.to>
date Sat, 23 Aug 2008 15:39:29 +0800
parents dd813dcc232c
children bd29780bf266
files examples/calculator/main.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/examples/calculator/main.c	Sat Aug 23 15:26:47 2008 +0800
+++ b/examples/calculator/main.c	Sat Aug 23 15:39:29 2008 +0800
@@ -47,7 +47,10 @@
 	r = v1 * v2;
 	break;
     case '/':
-	r = v1 / v2;
+	if(v2)
+	    r = v1 / v2;
+	else
+	    r = v1;
 	break;
     }