[英]How to put 2 char arrays in int putenv(char *string); in C
I am trying to set a variable name and variable value in the environment of Windows by using this function 我试图通过使用此函数在Windows的环境中设置变量名称和变量值
void env_add(char varname[], char varvalue[]) {
}
The problem is that i do not know how to put both of these variables to int putenv(char *string);
问题是我不知道如何将这两个变量都放到
int putenv(char *string);
Should I combine them into one char array or not? 我应该将它们组合成一个char数组吗?
Thank you 谢谢
Yes, you should combine them into a single string. 是的,您应该将它们组合成一个字符串。 The string has the form "name=value" .
该字符串的格式为“name = value” 。
char* buffer = (char*) malloc( strlen(name) + 1 + strlen(value) + 1 );
strcpy( buffer, name );
strcat( buffer, "=" );
strcat( buffer, value );
putenv( buffer );
free( buffer );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.