小编Joh*_*nyF的帖子

C编译:collect2:错误:ld返回1退出状态

我尝试在线搜索该bug,但所有帖子都是针对C++的.

这是消息:

test1.o:在函数ReadDictionary': /home/johnny/Desktop/haggai/test1.c:13: undefined reference toCreateDictionary'collect2:error:ld返回1退出状态make:***[test1]错误1

超级简单的代码,无法理解是什么问题

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dict.h"
#include "hash.h"


pHash ReadDictionary() {
    /* This function reads a dictionary line by line from the standard input. */
    pHash dictionary;
    char entryLine[100] = "";
    char *word, *translation;

    dictionary = CreateDictionary();
    while (scanf("%s", entryLine) == 1) { // Not EOF
        word = strtok(entryLine, "=");
        translation = strtok(NULL, "=");
        AddTranslation(dictionary, word, translation);
    }
    return dictionary;
}

int main() {
    pHash dicti;
...
Run Code Online (Sandbox Code Playgroud)

现在这是标题dict.h …

c linker compilation

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

在c中为日期和时间添加文件名

我正在寻找一种方法将当前日期和时间添加到我现在打开的日志文件中使用:

fopen("/var/log/SA_TEST","w");
Run Code Online (Sandbox Code Playgroud)

如何制作它

fopen("/var/log/SA_TEST_DATE_AND_TIME","w");
Run Code Online (Sandbox Code Playgroud)

很多(在c)

c

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

如何使用c检查linux中的端口是否空闲

我从来没有写过这样的东西,如何在Linux环境中使用c程序检查端口是否为空,非常感谢.

ps寻找方法,不使用bind或connect并检查它是否失败.

编辑我不能使用绑定或连接,寻找更快的方法来找到连续免费的3k端口

c linux

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

如何从邻接矩阵matlab获取距离矩阵

我有邻接矩阵让它被称为 A 大小 n*n

其中A(k,j)=A(j,k)=1如果k,j连接在1个一跳。

现在看起来如果我把

Dist=double(A)*double(A)>0 %getting all two hops connectivity
Dist=double(Dist)*double(A)>0 %getting all three hops connectivity 
Dist=double(Dist)*double(A)>0 %getting all four hops connectivity
Run Code Online (Sandbox Code Playgroud)

这完全正确吗?

我用一些简单的图表进行了尝试,它看起来是合法的

我可以使用这个事实来创建距离矩阵吗?

其中距离矩阵将显示从 j 到 k 的最小跳数

PS:

如果它合法,我会很高兴理解为什么它是正确的,现在确实在 Google 中找到了信息

algorithm networking matlab logic matrix

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

制作一个char数组错误

在更大的代码中我有这个代码:

#define N 10
..
..
..
char Map [N][N] =              {"##########",
                                "#@       #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "##########"};
Run Code Online (Sandbox Code Playgroud)

当我尝试编译并运行它代码bloke我给了我错误

F:\ C++\Maze\main.cpp | 25 |警告:扩展初始化列表仅适用于-std = c ++ 11或-std = gnu ++ 11 [默认启用] |

知道我在这个简单的代码中做错了什么吗?

c++

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

C typedef的功能,使用方法 - 简单的例子

我会表明我的意思:

标题:

#ifndef _HASH_H_
#define _HASH_H_
typedef void* pKey;

typedef int (*HashFunc) (pKey key, int size);
#endif
Run Code Online (Sandbox Code Playgroud)

新标题:

#ifndef _DICT_H_
#define _DICT_H_

#include "hash.h"

HashFunc HashWord;

#endif
Run Code Online (Sandbox Code Playgroud)

现在这里我不知道该写什么,我想写这个HashWord函数本身

c文件

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#include "dict.h"

typedef struct _wordElement {
    char* word;
    char* translation
} wordElement, *pwordElement;



HashFunc HashWord{
    ......... here i will want to write the Code
}
Run Code Online (Sandbox Code Playgroud)

现在它给了我一个错误,我该怎么写最后一行?

也许

HashFunc HashWord(pKey theKey,int number){...}
Run Code Online (Sandbox Code Playgroud)

也许

HashFunc HashWord( theKey, number){...}
Run Code Online (Sandbox Code Playgroud)

也许

int HashWord (pKey key, …
Run Code Online (Sandbox Code Playgroud)

c typedef function

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

睡眠功能在linux中的c疯狂bug

我有这个简单的代码"在int中的printinterval

sleep(printinterval/3);
displayPrint();  //// just some printing func
sleep(printinterval/3);
displayPrint(); 
sleep(printinterval-2*(int)(printinterval/3));
displayPrint(); 
Run Code Online (Sandbox Code Playgroud)

问题是它不能以正确的方式做延迟,跳过1次睡眠

sleep(printinterval/3);
printf("\n");
displayPrint();  //// just some printing func
printf("\n");    
sleep(printinterval/3);
printf("\n");    
displayPrint();
printf("\n"); 
sleep(printinterval-2*(int)(printinterval/3));
printf("\n");
displayPrint(); 
Run Code Online (Sandbox Code Playgroud)

奇迹般有效

有任何想法吗?谢谢 :)

编辑:thx的帮助发现这种方式来解决它

fflush(stdout); // Will now print everything in the stdout buffer
Run Code Online (Sandbox Code Playgroud)

thx

c linux

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

MATLAB从字符串中读取所有数字

我正在尝试从字符串中读取未知数量的数值.

例如:

line = 'bla bal bli : 3 5 12 15 266'
Run Code Online (Sandbox Code Playgroud)

我试过sscanf但它需要我知道字符串中有多少数字提前.

matlab parsing

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

MATLAB图 - 在绘图之前过滤数据

我有一个90x2矩阵a,其中a(:,1)是x,而a(:,2)是y.

我想只绘制y大于BOOM的值.我怎样才能做到这一点?

目前我有

plot(a(:,1),a(:,2));
Run Code Online (Sandbox Code Playgroud)

还有一件事,我怎样才能完整显示数字num*10^4呢?

matlab figure matlab-figure

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

MATLAB制作相交得更快

让两个{A,B}大小的数组1xN

我想找到相同指数的案例数量

条件A(ii)==1 & B(ii)==0得到满足.

我试过了

casess= intersect( find(A==1),find(B==0 ))
Run Code Online (Sandbox Code Playgroud)

但这很慢.

我相信这是因为intersect检查每个成员是否是另一个成员的成员,但我仍然在寻找解决我的小问题的最快解决方案.

optimization matlab set-intersection

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

与chdir的奇怪的臭虫在c

像prog一样建造一个小壳

我尝试制作cd命令,所以我使用:

if (!strcmp(cmd, "cd") ) 
    {
        if(chdir("args[1]")!=0){
            printf(" %s - path not found\n",args[1]);
            perror("Error:");
        }
    } 
Run Code Online (Sandbox Code Playgroud)

输出是这样的:

smash > cd /home/johnny/workspace/
 /home/johnny/workspace/ - path not found
Error:: No such file or directory
smash > cd test
 test - path not found
Error:: No such file or directory
Run Code Online (Sandbox Code Playgroud)

ps工作目录中有一个"test"文件夹

也许你们可以帮助我如何制作"cd .."命令

c unix linux chdir

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

如何从矢量C++中查找和删除项目

我有一个矢量:

std::vector<User*> myFriends_;
Run Code Online (Sandbox Code Playgroud)

然后我有代码来查看元素是否theFriend存在于向量中.

if (std::find(myFriends_.begin(), myFriends_.end(), theFriend)!=myFriends_.end())
            return FAILURE;
Run Code Online (Sandbox Code Playgroud)

我想做点什么

User* toErease;
toErease=std::find(myFriends_.begin(), myFriends_.end(), theFriend);
if (toErease!=myFriends_.end())
                return FAILURE;
myFriends_.erase(toErease); /// remove this element if its precent
Run Code Online (Sandbox Code Playgroud)

它会起作用吗?

find 返回元素的位置

erase据我所知,需要索引.

c++ vector

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