小编acc*_*sio的帖子

在c中使用带浮点数的offsetof

代码适用于int,但是当我想使用float时它会失败,除非我将结构转换为字符指针.这是它的样子:

struct test
{
    float a;
    float b;
};

void stuff(int offset, test* location);

int main()
{
    test *t;
    t = (test*)malloc(sizeof(test));

    char choice = '\0';

    //Find the byte offset of 'a' within the structure
    int offset;
    printf("Edit a or b?");
    scanf("%c", &choice);
    switch (toupper(choice))
    {

    case 'A':
        offset = offsetof(test, a);
        stuff(offset, t);
        break;
    case 'B':
        offset = offsetof(test, b);
        stuff(offset, t);
        break;
    }
    printf("%f %f\n", t->a, t->b);
    return 0;
}

void stuff(int offset, test* location)
{
    float imput; …
Run Code Online (Sandbox Code Playgroud)

c offsetof

4
推荐指数
1
解决办法
149
查看次数

$ scope.uiGrid未定义

我正在尝试使用angularjs ui-grid创建一个表,但我不断被告知$ scope.uiGrid是未定义的,有谁能告诉我我做错了什么?

    requestYelp.success(
    function(obj) 
    {
        console.log(obj.businesses[0].name);

        $scope.gridOptions = {
            enableSorting: true,
            rowHeight:100,
            columnDefs: [
            { field: 'name' },
            { field: 'company'  },
            { field: 'image', cellTemplate:"<img width=\"50px\" ng-src=\"{{grid.getCellValue(row, col)}}\" lazy-src>"}
            ],

            data:[
            {name:obj.businesses[0].name,company: "Company1", image: obj.businesses[0].image_url},
            {name:obj.businesses[1].name,company:"Company2",image:obj.businesses[1].image_url},
            {name:obj.businesses[2].name,company:"Company3",image:obj.businesses[2].image_url}
            ]
        };
    }
);
}]);
Run Code Online (Sandbox Code Playgroud)

console.log(obj.businesses[0].name)将把正确的数据放到控制台上,这对obj变量来说不是问题.代码只有在进入gridOptions时才会中断.

javascript angularjs mean-stack angular-ui-grid

4
推荐指数
1
解决办法
3349
查看次数

Node.js - "TypeError - res.setHeader不是函数"

我正在尝试将JSON从URL加载到变量并将其发送回客户端的javascript

var getJSON =require('get-json');

app.post('/json', function(req, res) {
    getJSON(url, function(err, res){
        if(err)
        {
           console.log(err);
        }
        else
        {
           res.setHeader('content-type', 'application/json');
           res.send(JSON.stringify({json: res.result}));
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

每次运行代码时,服务器都会说这res.setHeader不是一个函数而其余的都会中断.

javascript getjson node.js express

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