嗨,我在 Visual Studio 2008 上尝试此代码时无法找到编译错误的原因。我试图通过函数查看 char* 返回值的示例。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* getActiveModuleType(void);
void main()
{
char getActiveModuleBuff[128];
//error C2106: '=' : left operand must be l-value
getActiveModuleBuff = getActiveModuleType();
printf("Active module in well formatted (2): %s\n",getActiveModuleBuff);
exit(0);
}
char* getActiveModuleType(void)
{
char activeModule[128];
int tempBuffLen=0;
int nbActivemodule = 0;
char moduleA = 1;
char moduleB = 1;
char moduleC = 0;
char moduleD = 1;
int i = 0;
if(moduleA==1) {activeModule[i] ='A'; activeModule[i+1]=','; i= i+2;}
if(moduleB==1) {activeModule[i] ='B'; activeModule[i+1]=','; i= i+2;}
if(moduleC==1) {activeModule[i] ='C'; activeModule[i+1]=','; i= i+2;}
if(moduleD==1) {activeModule[i] ='D'; activeModule[i+1]=','; i= i+2;}
printf(" Active module in : %s\n",activeModule);
//let get get the last ',' value trucated
tempBuffLen = strlen(activeModule);
nbActivemodule = tempBuffLen/2;
if((tempBuffLen == 0) && (nbActivemodule ==0)){
memcpy(activeModule,"NoActiveModule",14);
return activeModule;
}
if(activeModule[tempBuffLen-1]==',')
activeModule[tempBuffLen-1] = '\0';
printf(" Active module in well formatted : %s\n",activeModule);
return activeModule;
}
我无法找到此代码中出现此错误 C2106 的原因。
需要帮助。
谢谢