使用gcc编译C时,预处理的.i文件中的数字含义是什么?

我想了解编译过程。 我们可以使用以下命令查看预处理器中间文件: gcc -E hello.c -o hello.i 要么 cpp hello.c > hello.i 我大致知道预处理器的作用,但我很难理解某些行中的数字。 例如: # 1 “/usr/include/stdc-predef.h” 1 3 4 # 1 “” 2 # 1 “hello.c” # 1 “/usr/include/stdio.h” 1 3 4 # 27 “/usr/include/stdio.h” 3 4 # 1 “/usr/include/features.h” 1 3 4 # 374 “/usr/include/features.h” 3 4 这些数字可以帮助调试器显示行号。 所以我对第一列的猜测是第2列文件的行号。 但是以下数字有什么作用?

替换字符串malloc中的字符

给定一个字符串和两个字符,我想找到第一个字符存在于字符串上的次数,它首先出现在什么位置并创建一个新字符串,其中第二个字符每次显示时都替换第一个字符,但我是最后一部分有问题。 这是我到目前为止: #include #include #include main () { char string[10], string1; char c1, c2; int contador, i, l, n, contador2; printf (“Introduza uma string e dois caracteres.\n”); scanf (“%s %c %c”, string, &c1, &c2); l = strlen (string); contador = 0; for (n = 0; n < l; n++) { if (c1 == string[n]) { […]

在Linux体系结构中使用C代码动态列出所有函数/符号?

假设main.c使用来自main.c声明的共享库和本地函数的符号。 是否有一种漂亮而优雅的方式在运行时打印所有可用function名称和符号的列表? 应该可以,因为数据被加载到.code段。

如何使用libcurl进行HTTP发布?

我是新用的libcurl。 我不清楚如何将它用于HTTP POST请求以及如何检查结果。 我怎么能用它呢?

请告诉我<>运算符在C中是如何工作的?

void main() { int x=5; printf(“%d%d%d \n”,x,x<>2); }

从文件中的数据结构写入字符串

该程序应该由用户接收一些输入字符串,将它们保存在数据结构中,然后将所有内容打印到文件中。 对于exaple,如果我输入“test one”,它应该保存在inputs.one上,然后我应该在clients.txt上看到“test one”。 如果我输入“test one”,“test two”和“test three”,我应该看到在clients.txt上打印的那三个输入。 问题是,程序现在只执行一次scanf而不是三次,这就是为什么我添加了三个scanf而不是只进行一次scanf。 基本上,如果我输入“测试一个”它只会保存并打印测试一个,而不需要另外两个输入,我不知道为什么。 额外:我添加了这些fgets作为另一种尝试正确保存输入的方法,问题是fgets会将文件上的数据打印为 “测试一次测试两次测试三次” 而不是一条线上的所有东西,所以fgets也不会工作。 #include #include #include struct inputs { char one[30]; char two[30]; char three[30]; }; int main(void) { struct inputs inputs = {“”, “”, “”}; FILE *cfPtr; // cfPtr = clients.txt file pointer // fopen opens file. Exit program if unable to create file […]

从指针中取消值

我很长时间没有做过指针运算,所以我想我会尝试用C做一个简单的二叉搜索树。 但是,我无法理解删除。 这些方面的东西像我期望的那样起作用: typedef struct Node{ int value; struct Node *left; struct Node *right; }Node; typedef struct Tree{ struct Node* root; }Tree; int main(){ Tree *tree = createTree(); treeInsert(10, tree); // Inserts 10 at root treeInsert(30, tree); // Inserts 30 to root->right treeInsert(5, tree); // Inserts 5 to root->left treeInsert(7, tree); // Inserts 7 to […]

类型转换为C中的unsigned

int a = -534; unsigned int b = (unsigned int)a; printf(“%d, %d”, a, b); 打印-534, -534 为什么没有发生类型转换? 我预计它会是-534, 534 如果我修改代码 int a = -534; unsigned int b = (unsigned int)a; if(a < b) printf("%d, %d", a, b); 它不打印任何东西……毕竟a小于b ??

clone()后通过指针访问父级中的变量

我很抱歉可能会问一个愚蠢的问题,但我是C的血腥初学者。现在我的问题是,我需要在子进程中访问两个变量,在main中声明并修改它们。 听起来很简单,但我必须使用克隆,并在将变量反向转换到我的数组之后,它们完全搞砸了关注值。 int main (){ uint64_t N = 10000000; uint64_t tally = 0; int status; void** child_stack = (void**)malloc(65536); uint64_t** package = (uint64_t**)malloc(sizeof(uint64_t*)*2); package[0] = &tally; package[1] = &N; pid_t cpid; cpid = clone(child_starter, &child_stack, CLONE_VM , (void*)package); waitpid(cpid, &status, __WCLONE); return 0; } child_starter函数如下所示: int child_starter(void* package){ printf( “Tally is in the child %” […]

与java相比,c中的openssl摘要不同

以下是代码,它是DigitalSigning Handler的一部分 final String NAMESPACEURI_WSSECURITY_WSU= “http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd”; final String NAMESPACEURI_WSSECURITY_WSSE = “http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext- 1.0.xsd”; final String NAMESPACEURI_XMLSIGNATURE_DS = “http://www.w3.org/2000/09/xmldsig#”; final String ATTRIBUTENAME_X509TOKEN = “http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile -1.0#X509v3”; final String ENCODINGTYPE_BASE64 = “http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message- security-1.0#Base64Binary”; SOAPHeaderElement securityElement = header .addHeaderElement(new QName( NAMESPACEURI_WSSECURITY_WSSE, “Security”, “wsse”)); //securityElement.setMustUnderstand(true); securityElement.addNamespaceDeclaration(“wsu”, NAMESPACEURI_WSSECURITY_WSU); securityElement.addNamespaceDeclaration(“ds”, NAMESPACEURI_XMLSIGNATURE_DS); SOAPBody body = envelope.getBody(); String bodyIdRef = “Id-1-BD-1”; body.addAttribute(new QName(NAMESPACEURI_WSSECURITY_WSU, “Id”, “wsu”), […]