小编Sha*_*ars的帖子

如何在Linux中启动GDB时传递命令行参数?

作为我的任务的一部分,我必须调试一个有错误的程序.但是,我必须首先传递命令行参数才能解决这个问题.

我做:

gdb -tui InsertionSortWithErrors
Run Code Online (Sandbox Code Playgroud)

哪个有效,但之后我不知道如何传递参数.我用过gdb -help,它说了一些关于--args我也尝试过的东西,它没有用.

我希望能够获得调试器+ gui并传递命令行参数.

c linux debugging gdb command-line-arguments

111
推荐指数
4
解决办法
15万
查看次数

如何在C中使用枚举

基本上我们必须为餐馆等待队列实现队列(链表).

我们获得了额外的积分,enum但我以前从未使用过它.我想知道我的使用方式是否合适?我查了一下,但没有看到任何使用链表的例子.

以下是我们结构的说明:

编写代码时,必须为等待列表的链表中的节点创建一个C结构.这些数据项必须包括以下内容(如果需要,可以包括其他数据项).

  • 组的名称

  • 指定组大小的整数变量(组中的人数)

  • 餐厅内的状态(使用枚举的额外分数!)

  • 指向列表中下一个节点的指针

餐厅状态是步入式或呼入式(提前打电话将名字放在等候名单上)

这是我的结构:

typedef struct restaurant
{
    char name[30];
    int groupSize;
    enum status{call, wait};
    struct restaurant *nextNode;
}list;
Run Code Online (Sandbox Code Playgroud)

我问,因为我在编译时收到此警告:

lab6.c:11:28: warning: declaration does not declare anything [enabled by default]
Run Code Online (Sandbox Code Playgroud)

c enums linked-list

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

代码说明(链表C)

这不是我的代码.我把这个代码从这个网站上删除了:

http://www.macs.hw.ac.uk/~rjp/Coursewww/Cwww/linklist.html

我正在使用有关如何构建链表的参考资料.我对发生的事情感到有些困惑.有人可以向我解释发生了什么事.我会用1-5来标记令我困惑的事情.

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

struct list_el {
   int val;
   struct list_el * next;
};

typedef struct list_el item;

void main() {
   item * curr, * head;
   int i;

   head = NULL;   //1

   for(i=1;i<=10;i++) {
      curr = (item *)malloc(sizeof(item));
      curr->val = i;
      curr->next  = head; //2
      head = curr; //3
   }

   curr = head; // 4

   while(curr) {  //5
      printf("%d\n", curr->val);
      curr = curr->next ;
   }
Run Code Online (Sandbox Code Playgroud)
  1. head = NULL→为什么head被设置为NULL?我知道你应该(我是出于习惯),但我不知道为什么.

  2. curr-> next = head→我也从未真正理解过这一点.也许我对"head"的定义错了,但是在常规链表中,它是列表中的起始节点还是最后一个节点?我一直认为它是起始节点,但在这一行中它看起来像是最后一个节点.

  3. head = curr→为什么我们将它设置为curr?

  4. curr = head→然后在循环完成后设置curr = …

c linked-list head

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

C中的浅拷贝和深拷贝

我尝试使用谷歌搜索,但只有反对的语言弹出结果.

根据我的理解,浅拷贝是复制结构的某些成员.

所以让我们说结构是

typedef struct node
{
    char **ok;
    int hi;
    int yep;
    struct node *next;
}node_t
Run Code Online (Sandbox Code Playgroud)

复制char**将是一个浅拷贝

但复制整个链表是一个深层复制?

我有正确的想法还是我离开了?谢谢.

c deep-copy shallow-copy

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

Why am I getting a an error when creating a generated column in PostgreSQL?

CREATE TABLE my_app.person
(
    person_id smallserial NOT NULL,
    first_name character varying(50),
    last_name character varying(50),
    full_name character varying(100) generated always as (concat(first_name, ' ', last_name)) STORED,
    birth_date date,
    created_timestamp timestamp default current_timestamp,
    PRIMARY KEY (person_id)
);
Run Code Online (Sandbox Code Playgroud)

Error: generation expression is not immutable

The goal is to populate the first name and last into the full name column.

sql postgresql database-design string-concatenation calculated-columns

9
推荐指数
2
解决办法
4432
查看次数

如何从C中的字符串中提取子字符串?

我尝试使用strncmp,但它只有在我给它一个特定数量的字节我想要提取时才有效.

char line[256] = This "is" an example. //I want to extract "is"
char line[256] = This is "also" an example. // I want to extract "also"
char line[256] = This is the final "example".  // I want to extract "example"
char substring[256]
Run Code Online (Sandbox Code Playgroud)

我如何提取""之间的所有元素?并把它放在变量substring?

c string c-strings

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

需要帮助使用广度优先搜索(Java)获得邻接矩阵(图形)的第n级

在此输入图像描述 在此输入图像描述

public int bfs(int maxDepth){
        int src = 2;
        int dest = 2;
        int i;
        int depth = 0;
        int countPaths = 0;
        int element;

        queue.add(src);

        while(!queue.isEmpty() && depth <= maxDepth)
        {   
            element = queue.remove();
            i = 0;

            while(i < 5) 
            {   
                if(arr[element][i] > 0)
                {
                    queue.add(i);

                    if(i == dest)
                        countPaths++;
                }       
                i++;
            }
        }

        queue.clear();
        return countPaths;
    }
Run Code Online (Sandbox Code Playgroud)

你好!!给定源和目的地,我需要找到一条路径.就遍历图表而言,我的BFS算法工作得很好.我的问题是当我想要它时停止它.我拿出了我增加深度的地方,所以我看起来不像是一个完全白痴.我希望有人能帮帮忙.基本上我想知道如何跟踪当前的深度.谢谢!

例:

找到从C到C的路径数,最多3个停靠点.答案是两条路:

C - > D - > C(2站)

C - > E - > B - > C(3站)

示例2:找到从A到C的路径数,最多3个停靠点.答案是三条路.

A …

java algorithm directed-graph breadth-first-search adjacency-matrix

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

用另一个结构体初始化一个结构体

如何将结构中的值分配给另一个结构。这是我的代码。

我相信我正在分配结构的地址,这是我不想做的。我想将“temp”的值分配给“a”。我评论了我需要帮助的部分。谢谢

也是题外话……我如何发布代码而不必逐行缩进自己?

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

#define SIZE 10

typedef struct dynArrStruct
{
    double value1;
    int value2;
    int value3;
}dynArr;


void init(dynArr* a)
{
    dynArr temp;
    temp.value1 = (double)(rand()) * rand() / rand();
    temp.value2 = rand()%100;
    temp.value3 = rand()%1000;
    printf("In init(): value1: %14.5f, value2: %6d, value3: %6d\n",
            temp.value1, temp.value2, temp.value3);
    a = &temp;  // THIS LINE
}


int main(int argc, char** argv)
{
    int i;
    dynArr a1[SIZE];
    dynArr* a2[SIZE];

    for(i = 0; i < SIZE; i++)
    {
        init(&(a1[i]));
        init(a2[i]); …
Run Code Online (Sandbox Code Playgroud)

c struct copy

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

需要帮助理解整数运算功能

请有人亲切地为我解释这个功能谢谢!

int overflow(int x, int y)
{
   int result, non_overflow, overflow, result_sign, mask;

   result = x + y;
   result_sign = result >> 31;  //Need help starting from here... I know
                                //it is shifting 31 bits... but why??
   non_overflow = ((x ^ y) | ~(y ^ result)) >> 31;
   overflow = ~non_overflow;

   mask = overflow << 31;

   return (non_overflow & result) | (overflow & (result_sign ^ mask));  
}
Run Code Online (Sandbox Code Playgroud)

c 32-bit integer-overflow integer-arithmetic

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

C中的内存地址

在主函数的最后一行,为什么&word2不同word2?假设正确的标题已到位.谢谢!

int main()
{
    char word1[20];
    char *word2;

    word2 = (char*)malloc(sizeof(char)*20);

    printf("Sizeof word 1: %d\n", sizeof (word1));
    printf("Sizeof word 2: %d\n", sizeof (word2));

    strcpy(word1, "string number 1");
    strcpy(word2, "string number 2");

    printf("%s\n", word1);
    printf("%s\n", word2);
    printf("Address %d, evaluated expression: %d\n", &word1, word1);
    printf("Address %d, evaluated expression: %d\n", &word2, word2); 
    //Why this one differ?
}
Run Code Online (Sandbox Code Playgroud)

c c-strings dynamic-allocation

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