小编xjs*_*16x的帖子

Javascript if语句不起作用

非常直接的我想做的事情:

  • 如果输入是0,则意味着他们没有输入数字,它应该告诉你.
  • 当输入是7,它应该说你做对了.
  • 还有别的,它应该告诉你,你弄错了.

但无论输入是什么,它只输出"7是正确的"线,我无法弄清楚出了什么问题.

<script type="text/javascript">
function problem2 ()
{
var number = 0;
var text=document.getElementById("output");
number = prompt("Enter a number between 1 and 10 please" , 0);
if (number = 0)
    {
     text.value = "You didn't enter a number!";
    }
if (number = 7)
    {
     text.value = "7 is correct!";
    }
else
    {
     text.value = "Sorry, ", input, "is not correct!";
    }
}
</script>
<input type="button" value="Click here" onclick="problem2()">
<input id="output" type="text">
Run Code Online (Sandbox Code Playgroud)

javascript if-statement

5
推荐指数
1
解决办法
2万
查看次数

C - exec没有输出到管道中

我正在制作一个程序,最终能够(理论上)为传递给它的任何shell命令工作.我的问题是运行的exec不会将其输出放入管道,而是在运行时看起来好像初始调用是进入管道而已?我试过先冲洗stdout但它不起作用.任何帮助表示赞赏!

int main(int argc, char *argv[]) {

    int i=0, pid;
    int dataPipe[2];
    pipe(dataPipe);

    char *newArgs[5] = {"/bin/sh", "-c", "ls", "-a", NULL};

    if ((pid = fork()) < 0) {

        printf("Error: could not fork!");
        exit(2);
    }

    else if (pid == 0) {

        close(dataPipe[0]);
        fflush(stdout);

        dup2(dataPipe[1], 1);
        close(dataPipe[1]);

        if (execvp(newArgs[0], newArgs) < 0) {

            printf("Command Failed to exucute!");
            exit(3);
        }
    }

    else {

        char buf[BUFFER];
        close(dataPipe[1]);

        wait(0);
        printf("Command exexuted correctly!\n");

        while(read(dataPipe[0], buf, BUFFER) != 0) {
            printf("Here is the command's output:\n%s\n", buf);
        } …
Run Code Online (Sandbox Code Playgroud)

c stdin stdout pipe exec

3
推荐指数
1
解决办法
660
查看次数

标签 统计

c ×1

exec ×1

if-statement ×1

javascript ×1

pipe ×1

stdin ×1

stdout ×1