简体   繁体   English

如何运行从 C 编译的 JS 脚本

[英]How to run JS script that is compiled from C

I need to understand how to run compiled JS script CORRECTLY because I got some erorrs.我需要了解如何正确运行已编译的JS脚本,因为我遇到了一些错误。

What I have:我拥有的:

#include <stdio.h>
#include <string.h>

void printNewLines(int amountOfNewLines);

int main() {
   char answerFromUser;

   printf("Hello man, I need you to enter single character. ");
   scanf("%c", &answerFromUser);
   printNewLines(3);
   printf("OMG, you entered: %c", answerFromUser);

   scanf(" %c", &answerFromUser); //To prevent immediate exit
   return 0;
}

void printNewLines(int amountOfNewLines)
{
   for (int newLine = 0; newLine < amountOfNewLines; newLine++)
   {
      printf("\n");
   }
}

When I compile it to JS and run using Emscripten on WSL, I get this:当我将它编译成 JS 并在 WSL 上使用 Emscripten 运行时,我得到了这个: 警告

And when I compile it with -o file.html option and try to paste script from JS file to Firefox console I get this:当我使用-o file.html选项编译它并尝试将脚本从 JS 文件粘贴到 Firefox 控制台时,我得到了这个: 警告

It seems even scanf() doesn't work.似乎连scanf()都不起作用。 So, what am I doing wrong and how to compile files properly?那么,我做错了什么以及如何正确编译文件?

Well, first of all I need to run HTTP server using node or something else.好吧,首先我需要使用node或其他东西运行 HTTP 服务器。 Then override window.prompt method to handle inputs from user.然后覆盖window.prompt方法来处理来自用户的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM