replit / ReplitClient.js

A JavaScript client library used to connect to the server-side code execution service
69 stars 13 forks source link

How to handle input? (scanf) #7

Open epiqueras opened 7 years ago

epiqueras commented 7 years ago

I have some code that looks like this:

repl.evaluate(
  '#include <stdio.h> \n int main() { printf("hello world"); int n = 0; scanf("%d", &n); printf("hello world"); return 0; }',
   {    
    stdout: function(str) {
      commandLine.append(str + '\n')
    }
   }
).then(function(result) {
    commandLine.append((result.error || result.data) + '\n');
  }, function(err) {
    commandLine.append(err + '\n');
  }
);

iText.keyup(function(e){
  if(e.keyCode == 13) {
    console.log(iText.val());
    iText.val('');
    repl.write(iText.val() + '\n');
  }
});

Without scanf it prints both "hello world"s.

With scanf I would except it to print the first one, wait for an input, and then print the second one. Instead, it doesn't print anything and it doesn't return any errors either. It lets me enter inputs (doesn't give the "you must evaluate before writing" error), but it doesn't return anything.