小编0x4*_*2D2的帖子

“if (isupper(argument) == true)”和“if (isupper(argument))”有什么区别?注意:参数是我程序中的任何字符

我正在做CS50的凯撒问题集,当我尝试移动大写字母时,if (isupper(argument) == true)用来检查我想要移动的字符是否为大写,它没有用,它认为大写字母实际上不是大写。当我将其切换到 时if (isupper(argument)),程序正确地移动了大写字母。这两种格式有什么区别吗?这是我使用的代码(我指的是 for 循环中的代码):

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    //Check wether there is only 1 command line argument
    if (argc == 2)
    {
        //Check if there is any character that's not a digit
        for (int i = 0; i < strlen(argv[1]); i++)
        {
            if (isdigit(argv[1][i]) == false)
            {
                printf("Usage: ./caesar key\n");
                return 1;
            }
        }
    }
    else
    {
        printf("Usage: ./caesar key\n"); …
Run Code Online (Sandbox Code Playgroud)

c cs50

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

加法问题,"整数"表现得像字符串

    var 
        calculator = document.calculator;
            input1 = calculator.input1;
            input2 = calculator.input2;
            result = calculator.result;
            equals = calculator.equals;

    function add(a,b) {
     equals.value = a+b;
    }

    result.addEventListener("click", function() {
     add.apply(add, [input1.value, input2.value]);   
    });

<form name="calculator">
    <input type="text" name="input1" /><br />
    <input type="text" name="input2" /><br />
    <input type="button" name="result" value="result" /><br /><br />
    <input type="text" name="equals" readonly="true" />
</form>
Run Code Online (Sandbox Code Playgroud)

它只返回数字 - 不添加.例如:5 + 3 = 53不是8.我该如何解决这个问题?

javascript

0
推荐指数
1
解决办法
2524
查看次数

你如何平衡文本框?

我有两个文本框想要弄平。平局,我的意思是:

[text] --> < input type="text" / >

[More more text] --> < input type="text" / >
Run Code Online (Sandbox Code Playgroud)

我希望两个“输入”彼此内联。如何移动第一个输入文本框以匹配由于“更多文本”而被进一步推动的第二个文本框的位置。

html web

0
推荐指数
1
解决办法
608
查看次数

这个JavaScript代码有什么问题?

var allHTMLElements = document.body.getElementsByTagName("*");
for (var i = 0; i < allHTMLElements.length; i++) {
    if (allHTMLElements[i].getAttribute("group") && allHTMLElements[i].getAttribute("index")) continue;
    allHTMLElements[i].style.color = "red";
}
Run Code Online (Sandbox Code Playgroud)
<div group="myGroup">Hello</div>
<div>Hello</div>
<div index="d534">Hello</div>
Run Code Online (Sandbox Code Playgroud)

所有div都变为红色,而具有组和索引的div不会保持默认颜色.只有中间应该变成红色,但事实并非如此.

javascript

0
推荐指数
1
解决办法
94
查看次数

0
推荐指数
1
解决办法
1261
查看次数

为什么这个setInterval代码不起作用?

我试图每秒改变身体的背景颜色,但它不起作用.我做错了什么?

var colors = [
    "red", "blue", "green", "yellow", "red"
    ],
    rand = Math.ceil(Math.random() * colors.length - 1),
    t = setInterval(function() {
        document.body.style.backgroundColor = colors[rand];
    }, 1000);
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
123
查看次数

为什么这个JSON.parse返回错误:"意外令牌非法"?

我正在使用AJAX请求.这是我第一次使用JSON或其中任何一种方法.ajax实用程序将onreadystatechange回调的参数作为我正在请求的文件的responseText或responseXML返回.使用一个简单的info.txt,request.responseText并将工作正常,但当我尝试它,当我多次检查我的语法是正确的时info.js,JSON.parse它返回"意外的令牌ILLEGAL".这是JSON:

JSON:

{
    first: 1,
    second: 2
}
Run Code Online (Sandbox Code Playgroud)

javascript

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

为什么这个循环不起作用?

这是一个非常简单的程序.我在顶部定义了一个函数,在循环中调用了函数print.

但我收到以下错误:

prog.cpp:5: error: variable or field ‘print’ declared void
prog.cpp:5: error: ‘a’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp:11: error: ‘print’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

这里是:

#include <iostream>    
using namespace std;

void print( a ) {
    cout << a << endl;
}

int main() {
    for ( int i = 1; i <= 50; i++) {
        if ( i % 2 == 0 ) print( i );
    }

    return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ for-loop

0
推荐指数
2
解决办法
991
查看次数

初学者使用对象和类得到以下错误

这是我一直在关注的教程,我已经完成了它所说的一切,但它不起作用。我有三个文件:main.cpp、burrito.h(类)和 burrito.cpp。

这里分别是三个文件。

主程序

#include <iostream>
#include "Burrito.h"
using namespace std;

int main() {

    Burrito bo;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

墨西哥卷饼

#ifndef BURRITO_H
#define BURRITO_H


class Burrito {
    public:
        Burrito();
};

#endif // BURRITO_H
Run Code Online (Sandbox Code Playgroud)

墨西哥卷饼

#include <iostream>
#include "Burrito.h"

using namespace std;

Burrito::Burrito() {
    cout << "Hello World" << endl;
}
Run Code Online (Sandbox Code Playgroud)

当我构建并运行时,出现以下错误:

...undefined reference to `Burrito::Burrito()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
1 errors, 0 warnings
Run Code Online (Sandbox Code Playgroud)

我正在使用 CodeBlocks 进行编译。

c++ codeblocks

0
推荐指数
1
解决办法
297
查看次数

练习模板返回错误

代码正在工作,couts haha但它会导致错误,因为它说:

Process returned -1073741819 <0xC0000005>

然后会弹出一个窗口,告诉我是否要发送错误消息.为什么是这样?

#include <iostream>

using namespace std;

template <class A>

    A print( A a ) {
        cout << a;
    }

template <class T>

    class David {
        T a;
        public:
            David( T something ) : a( something ) {}
            void laugh() {
                print(a);
            }
    };

int main() {

    David <string> Do("Hahaha");

    Do.laugh();

}
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
71
查看次数

标签 统计

javascript ×5

c++ ×3

c ×1

codeblocks ×1

cs50 ×1

for-loop ×1

html ×1

web ×1