现在我正在尝试这个:
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s %s sourcecode input", argv[0], argv[1]);
}
else {
char source[] = "This is an example.";
int i;
for (i = 0; i < sizeof(source); i++) {
printf("%c", source[i]);
}
}
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这也不起作用:
char *source = "This is an example.";
int i;
for (i = 0; i < strlen(source); i++){
printf("%c", source[i]);
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
Test.exe中0x5bf714cf(msvcr100d.dll)的未处理异常:0xC0000005:读取位置0x00000054时发生访问冲突.
(从德语松散翻译)
那我的代码出了什么问题?
所以我在这里有这个代码:
toWords :: String -> [String]
toWords "" = []
toWords (nr1 : rest)
| nr1 == ' ' = toWords rest
| otherwise = [nr1] : toWords rest
Run Code Online (Sandbox Code Playgroud)
"toWords"函数应该只删除所有空格并返回包含所有单词的列表.但这发生了:
*主要> toWords"你好吗?"
["你好吗","?"]
我的应用程序需要处理一些国际字符,即ä,ü,ö和ß,它们仍然是ascii.
当我在处理这些字符时测试ruby的行为时,我收到了这个错误:
test.rb:1: invalid multibyte char (US-ASCII)
test.rb:1: invalid multibyte char (US-ASCII)
Run Code Online (Sandbox Code Playgroud)
对于此代码:
puts "i like my chars: ä, ü, ö and ß!"
Run Code Online (Sandbox Code Playgroud)
但奇怪的是:当使用Interactive Ruby Shell时,我没有错误!
编辑:在我的应用程序中,我正在从外部API检索数据.上面的代码只是一个例子!
我正在努力解决Project Euler中的问题#5.该代码适用于该示例,当我检查从1到10的数字时,我得到2520,这是正确的.但是当我检查从1到20的数字时,代码不会停止运行.
这里是:
num = 0
while true
num += 1
check = true
for i in 1..20
break unless check
check = num%i==0
end
break if check
end
File.open("__RESULT__.txt", "w+").write num
Run Code Online (Sandbox Code Playgroud) 所以我有这个代码:
class Door
# ...
def info attr = ""
return {
"width" => @width,
"height" => @height,
"color" => @color
}[attr] if attr != ""
end
end
mydoor = Door.new(100, 100, "red")
puts mydoor.info("width")
puts mydoor.info
Run Code Online (Sandbox Code Playgroud)
如果没有提供参数,方法"info"应返回散列,否则返回散列中参数的值.我怎样才能做到这一点?