小编dea*_*ake的帖子

在头文件中使用结构"未知类型"错误

我在Kubuntu使用Kdevelop.我在datasetup.h文件中声明了一个结构:

#ifndef A_H
#define A_H

struct georeg_val {

    int p;
    double h;
    double hfov;
    double vfov;
};

#endif
Run Code Online (Sandbox Code Playgroud)

现在当我在main.c文件中使用它时

int main()
{
    georeg_val gval;

    read_data(gval); //this is in a .cpp file

}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

georeg_chain.c:7:3:错误:未知类型名称'georeg_val'

(这是georeg_val gval;在行)

如果有人能帮我解决这个错误,我将不胜感激.

c struct kdevelop header-files

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

使用strcpy时打印垃圾

我有一个函数可以解析一些数据.我的问题是在使用strncpy后,当我尝试打印它时会得到一些垃圾.我尝试使用malloc使char数组具有确切的大小.

码:

void parse_data(char *unparsed_data)
{
char *temp_str;
char *pos;
char *pos2;
char *key;
char *data;
const char newline = '\n';

int timestamp = 0;

temp_str = (char*)malloc(strlen(unparsed_data));

g_print("\nThe original string is: \n%s\n",unparsed_data);


//Ignore the first two lines
pos = strchr(unparsed_data, newline);
strcpy(temp_str, pos+1);
pos = strchr(temp_str, newline);
strcpy(temp_str, pos+1);

//Split the line in two; The key name and the value
pos = strchr(temp_str, ':'); // ':' divides the name from the value
pos2 = strchr(temp_str, '\n'); //end of the …
Run Code Online (Sandbox Code Playgroud)

c malloc parsing text strncpy

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

在C中实现队列

我正在尝试为Gstreamer缓冲区实现自定义队列.问题是,当我试图出列时,似乎我正在失去队列的头部.每当我尝试两次出队时,我都会遇到分段错误.我也注意到头部总是等于头部 - >下一个.现在我不确定入队或出队是否有问题.请帮帮我.谢谢.

typedef struct _GstBUFFERQUEUE GstBufferQueue;

struct _GstBUFFERQUEUE {
  GstBuffer *buf;
  guint buf_size;
  struct _GstBUFFERQUEUE *next;
};

void enqueue_gstbuffer(GstBufferQueue **head, GstBufferQueue **tail, guint *queue_size, GstBuffer *buf)
{
  if (*queue_size == 0)
  {
    *head = malloc(sizeof(GstBufferQueue));
    (*head)->buf = gst_buffer_try_new_and_alloc (GST_BUFFER_SIZE(buf));
    (*head)->buf = gst_buffer_copy(buf); 
    *tail = *head;
  }
  else
  {
    if ((*tail)->next = malloc(sizeof(GstBufferQueue))) {
        (*tail)->next->buf = gst_buffer_try_new_and_alloc (GST_BUFFER_SIZE(buf));
        (*tail)->next->buf = gst_buffer_copy(buf);
        (*tail) = (*tail)->next;
    }
    else {
        GST_WARNING("Error allocating memory for new buffer in queue");
    } 
  } 
  (*tail)->next = NULL; …
Run Code Online (Sandbox Code Playgroud)

c queue tail head gstreamer

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

使用C中的void指针修改原始文件

我试图通过引用将变量传递给void指针,以更新原始值.当我尝试它时,旧值永远不会更新.任何帮助将不胜感激. gst_filter_chain就像主要功能(Gstreamer)

void update_value(void *oldValue, void *newValue)
{
    oldValue = newValue;
}

void update_struct(myStruct *oldStruct, myStruct newStruct)
{
    update_value((void *)&oldStruct->a, (void *)&newStruct.a)
}

static GstFlowReturn
gst_filter_chain (GstPad * pad, GstBuffer * buf)
{
    GstFilter *filter= GST_FILTER (gst_pad_get_parent (pad));
    myStruct temp_data;

    int buf_size = GST_BUFFER_SIZE(buf);     
    if(buf_size > 1) //if buffer is not empty
    {
        if(!filter->is_init)
        {
            memcpy(&filter->data, GST_BUFFER_DATA(buf), sizeof(myStruct));
            filter->is_init = TRUE;
        }
        else
        {
            memcpy(&temp_data, GST_BUFFER_DATA(buf), sizeof(myStruct));
            update_struct(&filter->data, temp_data);
        }
    }   


    gst_buffer_unref(buf);
    return GST_FLOW_OK;
}
Run Code Online (Sandbox Code Playgroud)

c pointers pass-by-reference void void-pointers

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