我得到错误Uncaught TypeError: Cannot read property 'getContext' of null
和文件中的重要部分是......我想知道因为game.js在下面的目录中,它找不到画布?我该怎么办?
./index.html:
<canvas id="canvas" width="640" height="480"></canvas>
Run Code Online (Sandbox Code Playgroud)
./javascript/game.js:
var Grid = function(width, height) {
...
this.draw = function() {
var canvas = document.getElementById("canvas");
if(canvas.getContext) {
var context = canvas.getContext("2d");
for(var i = 0; i < width; i++) {
for(var j = 0; j < height; j++) {
if(isLive(i, j)) {
context.fillStyle = "lightblue";
}
else {
context.fillStyle = "yellowgreen";
}
context.fillRect(i*15, j*15, 14, 14);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 以下Makefile不起作用,我不确定发生了什么.
CC = gcc
CFLAGS = -Wall -g
demo:
${CC} ${CFLAGS} demo.c -o demo
lib:
${CC} ${CFLAGS} lib.c -o lib
clean:
rm -f lib demo
Run Code Online (Sandbox Code Playgroud)
Demo具有main函数,lib具有一组演示中使用的方法.
我在-cg中添加了-c标志.但是,当我运行make时,我得到:
Makefile:5: *** missing separator. Stop.
Run Code Online (Sandbox Code Playgroud) 我得到一个分段错误并使用gdb和backtrace,它被引发到vprintf.
#0 0x006e8779 in vfprintf () from /lib/libc.so.6
#1 0x006f265f in fprintf () from /lib/libc.so.6
#2 0x08049fd1 in write_tofile (logfile=0x9843090 "~/www/log") at example.c:446
Run Code Online (Sandbox Code Playgroud)
它在我打电话时发生
file = fopen(log_file, "a"); // log_file = "~/www/log"
fprintf(file, buffer);
Run Code Online (Sandbox Code Playgroud)
fopen可以处理来自不同目录的文件吗?有人会有一个线索,为什么它会在这里发生错误?
我想使用write(http://linux.about.com/library/cmd/blcmdl2_write.htm)将整数1写入第一个字节,将0x35写入文件描述符的第二个字节,但是当我发送时会收到以下警告尝试以下方法:
write(fd, 1, 1);
write(fd, 0x35, 1);
source.c:29: warning: passing argument 2 of ‘write’ makes pointer from integer without a cast
source.c:30: warning: passing argument 2 of ‘write’ makes pointer from integer without a cast
Run Code Online (Sandbox Code Playgroud) 我想用2个字符和一个向量(uint64_t)写入文件,但我首先必须将它们全部写入缓冲区.然后缓冲区将写入文件.我应该如何将这3个变量写入缓冲区(void指针),以便所有变量都包含在一个(void指针)变量中.
比如我想写
char a = 'a';
char b = 'b';
uint64_t c = 0x0000111100001111;
Run Code Online (Sandbox Code Playgroud)
成
void *buffer = malloc(sizeof(char)*2+sizeof(uint64_t));
Run Code Online (Sandbox Code Playgroud)
然后使用将其写入文件
write(fd, buffer, sizeof(char)*2+sizeof(uint64_t));
Run Code Online (Sandbox Code Playgroud) Sizeof打印出6:
printf("%d\n", sizeof("abcde"));
Run Code Online (Sandbox Code Playgroud)
但它打印出4:
char* str = "abcde";
printf("%d\n", sizeof(str));
Run Code Online (Sandbox Code Playgroud)
有人可以解释原因吗?
我想初始化一个具有X个二维元素的数组.例如,如果X = 3,我希望它是[[0,0],[0,0],[0,0]].我知道[0]*3给出[0,0,0],但我该如何为二维元素做这个呢?
我正在从Textmate切换到VIM,我想知道我的.vimrc中应该包含什么来获得类似的行为:
<tab>
将产生一个共同的'for'用途谢谢.
以下单例类工作正常,
public class Elvis
{
private static Elvis elvis = new Elvis();
private Elvis()
{
}
public static Elvis Instance()
{
return elvis;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我换return elvis;
到时return this.elvis
,我明白了non-static variable this cannot be referenced from a static context
.为什么是这样?
我有以下二进制数
uint64_t = 0b0100;
Run Code Online (Sandbox Code Playgroud)
我想否定它
0b1011
Run Code Online (Sandbox Code Playgroud)
这是一个具体的例子,但我希望它适用于任何二进制数变量。例如,
uint64_t a
那么是否有像 negate 这样的函数可以使以下内容成立
a == negate(negate(a));
Run Code Online (Sandbox Code Playgroud) 对于Python,我可以这样做array.index(element)
,以获得index
一个element
在array
.如何使用常规数组而不是arrayList在Java中执行此操作?有类似的功能吗?
需要快速帮助,但如何在Python中将[1,2,3]数组转换为字符串1 2 3?