在我的程序中,我想确定文件是否是ELF(可执行和可链接格式)类型.如何使用C语言函数识别文件是否是elf文件?
我有一个名为的日志文件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)
非常感谢!
我的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 …
如何模拟 HTTP 请求。例如,我想模拟向我的数据库中插入数据的请求,以检查我的程序的安全性和可靠性。有什么好的工具吗?
#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 } 。有相关资料吗?
谢谢。