Tag: c

替换字符串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 ??

与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”), […]

SConscript中的SharedLibrary的CCCOMSTR / LINKCOMSTR不起作用

我对SCons很新,并注意到当我在SConscript中构建共享库时,CCCOMSTR和LINKCOMSTR将无法工作。 这是我的SConstruct的简化版本: CFLAGS = [“-Wall”, “-pedantic”, “-std=c99”] # building environment env = Environment(CFLAGS = CFLAGS, CPPDEFINES = [“DEBUG”]) # checking dependencies conf = env.Configure() conf.CheckHeader(“stdlib.h”) conf.CheckHeader(“string.h”) conf.CheckLib(“libdl”) env[“CCCOMSTR”] = “Compiling $SOURCE …” env[“LINKCOMSTR”] = “Linking $TARGET …” SConscript(dirs = [“lib1”, “lib2”], exports=[“env”, “conf”], name = “SConscript”) # main function env.Program(target = “prog”, LIBS=[“libdl”], source = […]

如何在C中旋转1d数组的一部分?

我打印出一个6×6 1darrays,但想要逆时针旋转左上角3×3部分。 有算法吗? 将来我也想像右下3×3部分或右上3×3部分或左下3×3部分一样旋转。 a[0] a[1] a[2] a[3] a[4] a[5] a[1] a[2] a[8] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[0] a[7] a[14] a[9] a[10] a[11] a[12] a[13] a[14] a[15] a[16] a[17] —> a[6] a[12] a[13] a[18] a[19] a[20] a[18] a[19] a[20] a[21] a[22] a[23] a[18] a[19] a[20] a[21] a[22] a[23] a[24] a[25] […]