小编Set*_*hot的帖子

如何为函数指针创建typedef

我认为如果我为函数指针创建了一个typedef会更容易使用函数指针,但我似乎让自己绊倒了一些语法或用法或类似于函数指针的typedef,我可以使用一些帮助.

我有

int foo(int i){ return i + 1;}
typedef <???> g;
int hvar;
hvar = g(3)
Run Code Online (Sandbox Code Playgroud)

这基本上就是我想要完成的事情,我是一个相当新的C程序员,这让我太过分了.有什么替代<???>

c typedef function-pointers

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

在python中获取具有唯一数字的数字的最快方法是什么?

Lemme澄清:

什么是获得两个数字之间所有唯一数字的每个数字的最快方法.例如,10,000和100,000.

一些明显的将是12,345或23,456.我正试图找到一种方法来收集所有这些.

for i in xrange(LOW, HIGH):
  str_i = str(i)
  ...?
Run Code Online (Sandbox Code Playgroud)

python performance

8
推荐指数
2
解决办法
1105
查看次数

了解FFMPEG视频编码

从ffmpeg中的编码示例中得到了这个.我可以稍微关注音频编码的作者示例,但我发现自己迷茫地看着C代码(我在块编号中评论,以帮助我引用我正在谈论的内容)...

static void video_encode_example(const char *filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int i, out_size, size, x, y, outbuf_size;
FILE *f;
AVFrame *picture;
uint8_t *outbuf, *picture_buf;              //BLOCK ONE
printf("Video encoding\n");

/* find the mpeg1 video encoder */
codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
if (!codec) {
    fprintf(stderr, "codec not found\n");
    exit(1);                                //BLOCK TWO
}

c= avcodec_alloc_context();
picture= avcodec_alloc_frame();
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
/* frames …
Run Code Online (Sandbox Code Playgroud)

c video ffmpeg codec

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

Segfaulting只有没有valgrind

我用valgrind得到了最后的"完成"消息,并获得此退出报告:

==3434== HEAP SUMMARY:
==3434==     in use at exit: 8,432 bytes in 4 blocks
==3434==   total heap usage: 4,369 allocs, 8,037 frees, 377,356 bytes allocated
==3434== 
==3434== LEAK SUMMARY:
==3434==    definitely lost: 152 bytes in 1 blocks
==3434==    indirectly lost: 0 bytes in 0 blocks
==3434==      possibly lost: 0 bytes in 0 blocks
==3434==    still reachable: 8,192 bytes in 2 blocks
==3434==         suppressed: 88 bytes in 1 blocks
==3434== Rerun with --leak-check=full to see details of leaked memory
==3434== 
==3434== …
Run Code Online (Sandbox Code Playgroud)

c valgrind segmentation-fault

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

正则表达式匹配CSS颜色十六进制代码

这应该很容易......我正在尝试将css文件中的3个十六进制数字与ruby匹配.这就是我所拥有的......

File.open(ARGV[0], 'r') do |source|
  source.each { |line|
  puts line if line =~ /\h{3}/
}
end
Run Code Online (Sandbox Code Playgroud)

这不会在具有多个此类值的文件中返回任何内容.如果我改变线,line =~ /\h/那么几乎每一行都会被返回.我知道我必须遗漏一些基本的东西,但它是什么?

编辑.这是一些示例输入.有效的十六进制颜色当然可以是三个十六进制值组合,但是现在我只关注六个值的组合.

#captcha fieldset{border-top:1px solid #c0c0c0;border-bottom:1px solid#c0c0c0;margin:0;padding:10px}
#captcha legend{color:gray}
#captcha .divider{display:none}
#captcha .captcha_refresh{font-size: 9px;color:gray}
#captcha .captcha_other_options{padding-top:5px;font-size: 9px}
#captcha .recaptcha_text{font-size: 11px;line-height:16px}
#captcha .captcha_optout{font-size: 11px;padding:10px 0 5px}
#captcha #recaptcha_image{font-weight:bold;margin:10px 0 0 0}
#captcha #recaptcha_image a.recaptcha_audio_cant_hear_link{font-size: 9px;font-weight:normal}
#captcha .captcha_loading{border:0}
#captcha .captcha_image img{border:1px solid #c0c0c0}
#captcha .captcha_input input{direction:ltr;margin-top:4px;width:137px}
#captcha .captcha_input label{margin-right:4px}
.register #captcha .captcha_input label{color:#666;font-weight:bold}
#generic_dialog.captcha .generic_dialog_popup{width:340px}
Run Code Online (Sandbox Code Playgroud)

css ruby regex

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

如何在openCV2 python中保存视频的掩码

我可以从网络摄像头捕获视频并使用此代码保存

cap = cv2.VideoCapture(0)
fgbg= cv2.BackgroundSubtractorMOG()

fourcc = cv2.cv.CV_FOURCC(*'DIVX')
out    = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret,frame = cap.read()
    if ret:
        fgmask = fgbg.apply(frame)
        out.write(frame)          #Save it                                      
        cv2.imshow('Background Subtraction', fgmask)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break                 #q to quit                                    
    else:
        break                     #EOF                                          

cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

这按照人们的预期记录,并显示背景减法的内容.它将它保存到output.avi.一切都很好.但我无法保存前景蒙版,它给了我一个Could not demultiplex stream错误.(此行在上面的代码中更改).

out.write(fgmask)          #Save it    
Run Code Online (Sandbox Code Playgroud)

为什么是这样?当我从捕获中读取时,fgmask不是一个框架吗?

python opencv background-subtraction

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

不在C中从struct打印字符串

从C语言中的结构打印字符串有问题...

typedef struct box{
    char *REF_OR_SYS; int num, x, y, w, h, o;
}BOX;

sscanf(str, "%s %d %d %d %d %d %d", &label, &refNum, &x, &y, &w, &h, &o);
BOX detect = {label, refNum, x, y, w, h, o};
printf("\nLABEL IS %s\n", detect.REF_OR_SYS); //Prints out the String correctly
                                              //(Either the word REF or SYS)
return detect;
Run Code Online (Sandbox Code Playgroud)

当这个结构传递给另一个结构时,所有内容都显示在字符串的EXCEPT之外.

void printBox(BOX detect){
printf("Type: %s    Ref: %d    X: %d    Y: %d    W: %d    H: %d    O:%d\n", 
 detect.REF_OR_SYS, detect.num, detect.x, 
 detect.y, detect.w, detect.h, detect.o); …
Run Code Online (Sandbox Code Playgroud)

c string struct pointers

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

获取c信息的好方法是什么?

我的意思是这个问题与其他编程语言不同,我可以简单地谷歌"实现类似的接口java"或"图形绘制python",每当我谷歌一个C问题,似乎大多数结果是关于C#或C++

我试过说ANSI C或C99,但那不太成功.我把我的朋友在大学借给我的K&R C圣经,有没有哪些网站是明确的c源?

c reference

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

交替递增序列

早上-

我需要一个可以产生以下类型的序列的函数:

1, -1, 2, -2, 3...
Run Code Online (Sandbox Code Playgroud)

尾递归函数是否是处理此问题的最佳方法?有没有办法迭代地执行此操作而不是递归?

c recursion sequence

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

为什么这个泄漏记忆?(指针数组C)

Gmorning SO-

瓦尔格林德说:

==9735== 24,976 bytes in 446 blocks are definitely lost in loss record 9 of 9
==9735==    at 0x100012362: malloc (vg_replace_malloc.c:266)
==9735==    by 0x1000016F2: interpolate (in ./a.out)
==9735==    by 0x100000CFA: main (in ./a.out)
Run Code Online (Sandbox Code Playgroud)

让人惊讶.这是我的插值函数:

void interpolate(PDouble* evaluated, int doubleCount){
int i, j, k;
int boxCount = 0;
int frameCount = 0;

for(i=0; i<doubleCount; i++){
  boxCount = evaluated[i]->first->numBoxes;
  frameCount = evaluated[i]->gap;
  evaluated[i]->changeMatrix = (int***)malloc(boxCount*sizeof(int**));

for(j=0; j < boxCount; j++){
  evaluated[i]->changeMatrix[j] = (int **)malloc(ATTR * sizeof(int*));

  for(k=0; k < ATTR; …
Run Code Online (Sandbox Code Playgroud)

c malloc valgrind memory-leaks

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