小编ttw*_*ard的帖子

如何使用C语言函数识别文件是否是elf文件?

在我的程序中,我想确定文件是否是ELF(可执行和可链接格式)类型.如何使用C语言函数识别文件是否是elf文件?

c linux elf

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

如何使用sort命令仅通过Linux中的第一个字段对日志文件进行排序?

我有一个名为的日志文件a.log!我希望通过fisrt字段排序!如果两行具有相同的字段,则顺序为原始竞争对象!内容:

 1. 101  c
 2. 100  b
 3. 100  a
 4. 2    d
Run Code Online (Sandbox Code Playgroud)

我期待结果:

 1. 2    d
 2. 100  b
 3. 100  a
 4. 101  c
Run Code Online (Sandbox Code Playgroud)

所以我用这个命令!

sort -nt 't' -k 1 a.log 
Run Code Online (Sandbox Code Playgroud)

但结果是:

 1. 2    d
 2. 100  a
 3. 100  b
 4. 101  c
Run Code Online (Sandbox Code Playgroud)

非常感谢!

linux sorting

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

在C++函数参数列表中有String类型时,我可以使用C程序函数调用C++函数吗?

我的C程序应用程序需要调用C++函数.但是C++函数中有字符串类型.例如,我需要像这样写一个函数fooC():

//main.c:

void fooC()
{
   char* str = "hello";
   fooCPP(str);
}


//foo.cpp

void fooCPP(String& str)
{
  ......
}
Run Code Online (Sandbox Code Playgroud)

如何正确编写代码?

更新

//hello.cpp 
#include <iostream>
#include <string>
#include "hello.h"
using namespace std;

void fooCpp(char const* cstr){
    std::string str(cstr);
    cout << str <<endl;
}

//hello.h
#ifdef __cplusplus
extern "C"{
#endif
void fooCpp(char const* str);

#ifdef __cplusplus
}
#endif

//main.c
#include "hello.h"

int main()
{
    char* str = "test"  ;
    fooCpp(str);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译:

g ++ -c hello.cpp hello.h

gcc hello.o main.c -g …

c c++ compiler-construction linker

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

如何模拟HTTP请求?

如何模拟 HTTP 请求。例如,我想模拟向我的数据库中插入数据的请求,以检查我的程序的安全性和可靠性。有什么好的工具吗?

php networking jquery http request

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

如何用ASCII码移动终端光标?

#include <stdio.h>
int main()
{
    printf("asd");
    char code[4] = { 0x08 ,  0x1b , 0x5b ,0x4b } ; 
    int i = 0 ; 
    while ( i  < 4  )
    {   
        putc(code[i], stdout);
        i++;
    }   
    printf("\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

[root@localhost ~]# ./a.out

作为

[root@localhost ~]#

似乎代码 "0x08" 将终端光标向左移动到字母 "d" 位置,而 "0x1b , 0x5b ,0x4b" 清除字母 "d" 。我想知道一些代码的含义,比如 { 0x08 , 0x1b , 0x5b ,0x4b } 。有相关资料吗?

谢谢。

c bash terminal ncurses

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

标签 统计

c ×3

linux ×2

bash ×1

c++ ×1

compiler-construction ×1

elf ×1

http ×1

jquery ×1

linker ×1

ncurses ×1

networking ×1

php ×1

request ×1

sorting ×1

terminal ×1