我正在做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) 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.我该如何解决这个问题?
我有两个文本框想要弄平。平局,我的意思是:
[text] --> < input type="text" / >
[More more text] --> < input type="text" / >
Run Code Online (Sandbox Code Playgroud)
我希望两个“输入”彼此内联。如何移动第一个输入文本框以匹配由于“更多文本”而被进一步推动的第二个文本框的位置。
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排序方法对数字数据进行排序 - 是真还是假?
我试图每秒改变身体的背景颜色,但它不起作用.我做错了什么?
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) 我正在使用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) 这是一个非常简单的程序.我在顶部定义了一个函数,在循环中调用了函数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) 这是我一直在关注的教程,我已经完成了它所说的一切,但它不起作用。我有三个文件: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 进行编译。
代码正在工作,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)