我正在尝试为我的项目创建过程。我会通过从父母的子进程中获得参数,并且参数会及时更改,所以我想先尝试将1传递给子进程。字符串格式应该是这样的“childname.exe c”,其中c表示随机字符(在这种情况下,仅用于试用)。从字符串数组中获取第一个字符串c
我创建了一个childname数组,并且我想要的是将新的字符串与childname字符串连接起来,并将其复制到另一个字符串数组(lpCommandLine变量)。当我调试下面的代码时,我看到child_name [0](当我等于0时)只返回'C',但我期望它返回“ChildProj1.exe”。有没有一点我错过了或如何在c中完成?
这里有什么,我getin调试器图像:here stored values of in variables
#define NO_OF_PROCESS 3
char *child_names[]= {"ChildProj1.exe", "ChildProj2.exe", "ChildProj3.exe" };
char* lpCommandLine[NO_OF_PROCESS];
int i;
for (i = 0; i < NO_OF_PROCESS; i++)
lpCommandLine[i] = (char *)malloc(sizeof(char) * 16);
for (i = 0; i < NO_OF_PROCESS; i++)
{
strcat_s(child_names[i], strlen(child_names[i]), " 1");
strcpy_s(lpCommandLine[i], strlen(lpCommandLine[i]), child_names[i]);
}
你认为在新的字符串“ 1”将被存储。 strcat_s失败,因为您尝试向缓冲区添加字符 - 请检查srcat_s的返回值 –
pm100
@ Y.E.S。目前还不清楚你将在数组lpCommandLine中获得什么。显示其结果内容。 –
我希望它被存储在lpCommandLine中。在child_names数组中,第0个字符串是“ChildProj1.exe”,我希望lpCommandLine [0]是“ChildProj1.exe 1”。那么你是否建议为16个字符的每个child_names索引分配内存,这意味着ChildProj1.exe + 3(对于空白和1和\ 0) –