小编Mas*_*man的帖子

CLion在调试中不会显示输出

当我启动程序时,这是输出:

-------------------- HASHMAP MANAGEMENT BOOT MENU -------------------------
Would you like to:
(a) create a new hashmap
(b) load an existing one
(q) exit
>
Run Code Online (Sandbox Code Playgroud)

但是,在调试时,这些都不会显示。检查调试,它确实检查了printf()命令,但它只是拒绝让它们显示在控制台中。输入寄存器,但输出永远不会到来。

int main(void){
    bool on = true;
    char choice = ' ';
    int status = 0;
    while(on){
        if(status == -1){
            printf("\n[ERROR] : HASHMAP NOT INITIALISED\n");
        }
        printf("\n-------------------- HASHMAP MANAGEMENT BOOT MENU -------------------------\n");
        printf("Would you like to:\n(a) create a new hashmap\n(b) load an existing one\n(q) exit\n> ");

        scanf("%c",&choice);
        ...
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

这是代码开始的样子,不包括所有#includes。另外,由于某种原因,CLion说我正在构建的代码task2-a.c | …

c debugging clion

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

C - printf("\a") 不会发出警报

这是我的 C 代码。

#include <stdio.h>

int main(){
   printf("\a\n");
   printf("Startled by the sudden sound, Sally shouted, \"By the Great Pumpkin, what was that!?\"");
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

据说,“\a\n”应该发出警报,对吗?然而,出于某种原因,它并没有这样做。我在 Ubuntu Zesty 上,bash 命令beep确实发出哔哔声,但echo -e '\a'没有,所以我不确定问题到底是什么。

提出这个问题是因为其他这样的问题最终没有产生对我来说足够详细/可以理解的答案,或者有一个完全不同的问题,其解决方案不适用于我。

坦率地说,上面链接的帖子的答案太模糊了。“问题不在于 C,而在于别的东西。” 根本没有帮助。

更新:以防万一其他人偶然发现了这一点,这是问题所在:我有 GNOME,因此 WM 是 Gnome-Shell。既然是这样,我就不得不打开声音设置,转到警报,启用它们,并调高音量。我从来没有注意到外壳本身可能是问题所在。在跑步后metacity --replace突然能够听到警报后意识到这一点。

c bash alert

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

C - 一行代码正在改变结构的地址

我的代码中发生了一个重大问题,我现在一直试图修复几个小时.

下面的代码是与我所遇到的问题相关的代码......

方法addBucket:

void addBucket(SPACE * hashmap,char * tempvalue, char * tempkey){
    printf("BEGINNING OF FUNC...\n");

    void *prevadd = hashmap[0];
    char *value = varString(tempvalue);
    char *key = varString(tempkey);
    void *aftadd = hashmap[0];

    printf("BUCKET %s - %s\n",value,key);

    BUCKET *newBucket = malloc(sizeof(BUCKET *));
    fillBucket(value,key,newBucket);
    int hash = hashFunc(key);

    printf("FILL, FULFILLED\n");

    if(!hashmap[hash]){
        hashmap[hash] = malloc(sizeof(BASE*));
        hashmap[hash]->first = NULL;
    }

    ITEM *location;
    location = hashmap[hash]->first;

    //This creates a new item in the list, if there isn't any.
    //It does this by initialising the base, called …
Run Code Online (Sandbox Code Playgroud)

c struct pointers memory-management memory-address

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

json_encode 不适用于数组

我正在使用 MySQL 在数据库中存储项目列表,并尝试从单个表中检索所有项目。连接部分工作正常,检索项目似乎工作得很好,但我无法对项目列表进行 json_encode。

  // Executes SQL query on the database specified by $con
  $sql = "SELECT * FROM productlist";
  $query = mysqli_query($con, $sql) or die(nl2br("\n Failed to execute query"));

  // Retrieves all the rows returned by the SQL query
  $rows = array();
  while($r = mysqli_fetch_assoc($query)) {
      $rows[] = $r;
  }

  echo json_encode($rows[0]); // test whether retrieval works

  // Displays rows in content-type JSON and in PRETTY_PRINT
  header('Content-Type: application/json');
  echo json_encode($rows, JSON_PRETTY_PRINT);
Run Code Online (Sandbox Code Playgroud)

这是代码。的json_encode效果rows[0]很好。但是,当我将其注释掉并尝试对 执行相同操作时rows,它什么也没有返回。 …

php arrays json

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

标签 统计

c ×3

alert ×1

arrays ×1

bash ×1

clion ×1

debugging ×1

json ×1

memory-address ×1

memory-management ×1

php ×1

pointers ×1

struct ×1