小编nic*_*ame的帖子

C - 奇怪的原型论证

这个函数原型发生了什么?显然,带有某种类型转换的void参数令人困惑......

int *my_func(my_struct *m, void (*m_op)(my_struct *v, void arg));
Run Code Online (Sandbox Code Playgroud)

c prototype void

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

ANSI C - 比较奇数

我想比较一个整数和一个双:

printf("%d\n", pos<(td+tr));
            if(td <= pos < (td+tr))
            {}
Run Code Online (Sandbox Code Playgroud)

print语句pos<(td+tr)正确评估比较.在if(td <= pos < (td+tr))比较不正确评估.

Pos是一个int:int pos; td和tr是双精度:double td,tr;

c compare

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

C - 将指针传递给函数,然后将函数内部的相同指针传递给另一个函数

呼!长标题......这里有一些伪代码来解释这个词:

int main(){
int* ptr = function1(); //the data that ptr points to is correct here
function2(ptr);
}

int function2(int* ptr){
//the data that ptr points to is still correct
int i;
for(i=0;i<length;printf("%d\n", (*ptr)[i]), i++); //since ptr points to a contiguous block of memory
function3(ptr);
}

int function3(int* ptr){
//the data that ptr points to is INCORRECT!!!
}
Run Code Online (Sandbox Code Playgroud)

为什么function3中的数据不正确?

注意:function1执行malloc()并返回指向该内存的指针.

实际代码

#include <stdlib.h>
#include <stdio.h>

//Structures
struct hash_table_data_
{
  int key, data;
  struct hash_table_data_ *next, *prev;
};

struct hash_table_
{ …
Run Code Online (Sandbox Code Playgroud)

c pointers function

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

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

ANSI C - 作为其他函数的参数的函数

我有这些原型:

int *my_func(int x, void (*other_func)(int a, int b));

int func2(int val1, int val2);
Run Code Online (Sandbox Code Playgroud)

假设有一个匹配它的函数.

如果我想实际调用my_func,我该怎么做?我试过以下没有运气:

my_func(1,func2);
Run Code Online (Sandbox Code Playgroud)

这是错误:

warning: passing argument 2 of ‘my_func’ from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)

c function-pointers ansi

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

C - fscanf() - 将数据读入数组

将数据读入数组时遇到奇怪的错误.我的目标是逐行读取具有单列数字的文件到一个数组中.

#include <stdio.h>

int main() {
    int numArray = [20];
    int i = 0;

    FILE *infile;
    infile = fopen("numbers", "r");

    while(!feof(infile))
    {
        fscanf(infile,"%d",&numArray[i]);
        i++;
    }

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

这是我的编译错误:

sort_algorithms.c:在函数'main'中:sort_algorithms.c:6:错误:在'['标记sort_algorithms.c:16之前的预期表达式:错误:下标值既不是数组也不是指针

c arrays scanf

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

MATLAB - 为什么这不起作用?

我很难过.MATLAB的语法是怎么回事?

clear all;

dx = .1;
x=-2:dx:2;
f=zeros(length(x),1);
int_f=zeros(length(x),1);
for n=1:length(x)
    f(n)=x(n).^2;
    int_f(n) = f(n)*dx+int_f(n);
end
plot(x,int_f(n));
Run Code Online (Sandbox Code Playgroud)

matlab

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

标签 统计

c ×6

ansi ×1

arrays ×1

compare ×1

function ×1

function-pointers ×1

matlab ×1

pointers ×1

prototype ×1

scanf ×1

void ×1