tangent icon

MiniBasic script driver C++ conversion

tangent | PRO | 07/20/14 04:50:16 AM UTC | 0 ⭐ | 837 👁️ | Never ⏰ | []
text |

1.37 KB

|

None

|

0 👍

/

0 👎

--- script-original.c	2014-07-19 22:36:49.000000000 -0600
+++ script.cpp	2014-07-19 22:47:53.000000000 -0600
@@ -4,17 +4,19 @@
   Leeds University
 */
 -#include <stdio.h>
+#include "basic.c"
+
+#include <iostream>
 #include <stdlib.h>
 -#include "basic.h"
+using namespace std;
  char *loadfile(char *path);
  /*
   here is a simple script to play with 
 */
-char *script =
+const char *script =
 "10 REM Test Script\n"
 "20 REM Tests the Interpreter\n"
 "30 REM By Malcolm Mclean\n"
@@ -28,10 +30,10 @@
  void usage(void)
 {
-  printf("MiniBasic: a BASIC interpreter\n");
-  printf("usage:\n");
-  printf("Basic <script>\n");
-  printf("See documentation for BASIC syntax.\n");
+  cout << "MiniBasic: a BASIC interpreter\n";
+  cout << "usage:\n";
+  cout << "Basic <script>\n";
+  cout << "See documentation for BASIC syntax.\n";
   exit(EXIT_FAILURE);
 }
 @@ -77,7 +79,7 @@
   fp = fopen(path, "r");
   if(!fp)
   {
-    printf("Can't open %s\n", path);
+    cout << "Can't open " << path << "\n";
 	return 0;
   }
 @@ -85,10 +87,10 @@
   size = ftell(fp);
   fseek(fp, 0, SEEK_SET);
 -  answer = malloc(size + 100);
+  answer = (char*)malloc(size + 100);
   if(!answer)
   {
-    printf("Out of memory\n");
+    cout << "Out of memory\n";
     fclose(fp);
 	return 0;
   }
@@ -101,4 +103,4 @@
   fclose(fp);
    return answer;

Comments