通过C中的argv使用管道发送和接收字符数组

所以,我正在尝试创建一个管道,通过argv []连接的管道来回发送char数组。 现在,我一直坚持在接口中接收数组(从父节点发送到子节点的c_param的参数)。在db.c中接收字符3和5。 我知道3和5是我的管道所在的argv []的索引,但我不知道如何接受它并在db.c中打印出我的消息。 interface.c创建管道,分叉到父进程和子进程。 char数组param被转移到子进程到char数组c_param。 使用snprintf,我将我的管道变成了一个char,使用execl和我的char数组c_param发送。 interface.c: int main (int argc, char *argv[]) { int to_Child[2]; int to_Parent[2]; int id, toChildPipe, toParentPipe, err; char param[100] = “This is the parameter!”; char sendPipe[100]; char recPipe[100]; /*CREATING PIPE*/ toChildPipe = pipe(to_Child); toParentPipe = pipe(to_Parent); if(toChildPipe == -1 || toParentPipe == -1) { printf (“Error on […]

动态地在C可执行文件中包含文本

对C和编译语言来说非常新。 我需要在此代码中基本上包含来自另一个文件的一行动态文本: #if T2T_NDEFFILE_PREDEF == URI const uint8_t T2T_DATA_DEF[] = { #include “/home/link” // Terminator TLV 0xF3 }; #endif 我已经尝试使用#include链接到文本文件,但是当文件“链接”中的文本发生更改时,它显然不会在编译的可执行文件中更改。 有没有简单的方法来做到这一点?

创建数组的动态声明

我想要动态声明的make数组我想象像这样的somethnig。我想要make程序识别单词中的字符。 char i; scanf(“%c”,&i); char word[]=i; printf(“%c”,word[0]); 我也试过这样的事情 char i; scanf(%c,&i); char *word=i; printf(“%c”,word[0]); 我不知道如何使它工作

在分隔符处拆分字符串并将子字符串存储在C中的char **数组中

我想编写一个函数,通过第一次出现的逗号将用户在命令行上给出的字符串拆分并放入数组中。 这是我尝试过的: char**split_comma(const str *s) { char *s_copy = s; char *comma = strchr(s_copy, “,”); char **array[2]; *(array[0]) = strtok(s_copy, comma); *(array[1]) = strtok(NULL,comma); return array; } 这是主要function: int main(int argc, char **argv) { char **r = split_comma(argv[1]); printf(“substring 1: %s, substring 2: %s\n”, r[0],r[1]); return 0; } 有人可以给我一些见解,为什么这不起作用?

如何在C中创建一个虚拟shell?

我有一个带有参数的虚拟shell程序。 但是,我希望它不带参数,而是提示让用户输入可执行程序和参数的名称。 例如: $dummyshell >(executable program and parameters go here) 这是我到目前为止的代码: #include #include #include #include #include #include #define BUFFER_SIZE 1<<16 #define ARRAY_SIZE 1<= &bufCmdArgs[cmdArgsSize])) break; } for (p=n=0; bufCmdArgs[n]!=NULL; n++){ if(strlen(bufCmdArgs[n])>0) cmdArgs[p++]=bufCmdArgs[n]; } *nargs=p; cmdArgs[p]=NULL; } int main(int argc, char *argv[], char *envp[]){ char buffer[BUFFER_SIZE]; char *args[ARRAY_SIZE]; char hflag = ‘N’; int *retStatus; size_t nargs; […]

C trie试图添加撇号

我正在尝试在C中编写一个trie来读取文件并将文件中的所有单词添加到trie中,并且它运行良好,但我不能让它接受撇号: typedef struct node { bool wordBool; struct node* next[27]; // 26 letters and one space for the apostrophe } node; node* base; int numWords = 0; bool load(const char* dictionary) { FILE* dictionaryf = fopen(dictionary, “r”); // the file to read base = malloc(sizeof(node)); node variable; node *currNode = &variable; int n = 0; […]

项目欧拉#8

我试着自己解决这个问题,但一段时间后卡住了,所以看了解决方案。 问题#8 。 这就是我得到的。 #include int main(void) { char str[] = “73167176531330624919225119674426574742355349194934” “96983520312774506326239578318016984801869478851843” “85861560789112949495459501737958331952853208805511” “12540698747158523863050715693290963295227443043557” “66896648950445244523161731856403098711121722383113” “62229893423380308135336276614282806444486645238749” “30358907296290491560440772390713810515859307960866” “70172427121883998797908792274921901699720888093776” “65727333001053367881220235421809751254540594752243” “52584907711670556013604839586446706324415722155397” “53697817977846174064955149290862569321978468622482” “83972241375657056057490261407972968652414535100474” “82166370484403199890008895243450658541227588666881” “16427171479924442928230863465674813919123162824586” “17866458359124566529476545682848912883142607690042” “24219022671055626321111109370544217506941658960408” “07198403850962455444362981230987879927244284909188” “84580156166097919133875499200524063689912560717606” “05886116467109405077541002256983155200055935729725” “71636269561882670428252483600823257530420752963450”; size_t len = sizeof str – 1; size_t i; unsigned max = 0; for (i = 0; i < len-4; i++) { unsigned p […]

使用libssh链接期间未定义的符号

我使用libssh来完成两个系统之间的连接,ssh服务器是redhat,客户端是CentOS。 我的代码编译和链接就好了,除了在运行时我一直看到这个, [1] libssh 0.5.5 (c) 2003-2010 Aris Adamantiadis (aris@0xbadc0de.be) Distributed under the LGPL, please refer to COPYING file for information about your rights, using threading threads_noop [2] Nonblocking connection socket: 4 [2] Socket connecting, now waiting for the callbacks to work [1] Socket connection callback: 1 (0) [1] SSH server banner: SSH-2.0-OpenSSH_5.3 [1] Analyzing […]

C指针:struc * A,struct * A和struct * A之间有什么区别?

我正在做一些研究以更好地理解C中的指针,但我很难理解这些:’struct * A’是结构上的指针吗? 那么什么是’struct * A’? 而且我看到有人写’int const * a’,这是什么意思?

g_signal_connect“pad-added”不起作用

我正在尝试学习如何在gstreamer中使用动态垫。 所以我尝试添加pad-added信号,这样我就可以在创建元素后收到消息。 但是,我没有收到任何消息。 这是代码: #include static void cb_new_pad (GstElement *element, GstPad *pad, gpointer data) { gchar *name; name = gst_pad_get_name (pad); g_print (“A new pad %s was created\n”, name); g_free (name); /* here, you would setup a new pad link for the newly created pad */ } int main (int argc, char *argv[]) { GstElement […]