c-无法解决预期的表达式错误



我因为一个错误被困了一个小时,这让我很生气。我有以下代码(当然在主要功能内部(:

if (GSM_Available()){
//1st, we'll see if some SMS are stored in the memory.
if(send_AT_command_UART("AT+CMGR=1,0","OKr") == 1){
//If we receive an ok, it means that there is no sms received recently.
continue;
}else{
//If we arrive here, we know that there is at least one recently received sms.
//We have to read the UART string received (the answer from the AT command) in order to retrieve the SMS from it.
char *answer;
int y=0;
char *newSensorAdress;
//char bidule[2][64]; //Array which will contain the alert threshold temperature, the humid
UARTReadString(answer,128);
//Ok now we have the answer. We have to take the "data" field from the answer.
for(int i=0;i<strlen(answer);i++){
//Ok, so from m66 datasheet we know that the text of the received sms is located right after a carriage return plus a line feed characters.
if(answer[i-1] == 'r' || answer[i] == 'f'){
//We now know that the sms starts at this index, after these 2 characters.
y=i;
}
}
//Now, we iterate over the sms field to find what kind of sms it is (if it is an expected sms, or a bullshit sms)
//1st character of the sms (e.g y+1) will determine the kind of frame we receive.
switch(answer[y+1]){
case 1:
//Here, it is the frame which says the address of the sensor to add to the network. We'll write this sensor into the EEPROM
//The frame is in this format : 1;abcdabcd. With the sensor's addressee starting at the first 'a'
//So, we'll iterate, and the index starts at y+3 (y+2 is ';')
int indexNewSensor=0;
for(int i = y+3;i<strlen(answer);i++){
//The address is for now received as a string
strcpy(newSensorAdress[indexNewSensor],answer[i]);//Filling the newSensorAdress string. Sensor
indexNewSensor++;
}
//Then, once filled, this address must be written into the EEPROM for the central station to remember it
break;
case 2:
//Here, it is the frame which says the address of the sensor to delete of the network. We have to delete the addressee of the network from the EEPROM
//For now, I don't know
break;
case 3:
//Here, it is the frame which sends the boundary temperature, boundary humidity temperature, measurement frequency
char *sub_string="";
int newIndex=0;
//1st, we'll fill a new string containing ;ab;ab;abcd
for(int i = y+2;i<strlen(answer);i++){
strcpy(sub_string[newIndex],answer[i]);
newIndex++;
}
//Now, we'll look for the delimiters, and put in a array of string each substring
char *pch = strtok(sub_string,";");
break;
default:
//Here, we have to deal when the 1st character is not a number, which means it does not match any known frame
//We just have to ignore the sms
break;
}
}
}

这是我得到的错误:

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/Projet_vigne/vigne_last'
make  -f nbproject/Makefile-default.mk dist/default/production/vigne_last.production.hex
make[2]: Entering directory 'D:/Projet_vigne/vigne_last'
"C:Program Files (x86)Microchipxc8v2.10binxc8-cc.exe"  -mcpu=18F46K22 -c  -fno-short-double       -fno-short-float -memi=wordwrite -fasmfile -maddrqual=ignore -xassembler-with-cpp -Wa,-a -DXPRJ_default=default  -msummary=-psect,-class,+mem,-hex,-file  -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits   -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto     -o        build/default/production/main.p1 main.c 
make[2]: *** [build/default/production/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
main.c:212:25: error: expected expression
int indexNewSensor=0;
^
main.c:215:52: error: use of undeclared identifier 'indexNewSensor'
strcpy(newSensorAdress[indexNewSensor],answer[i]);//Filling the      newSensorAdress string. Sensor
^
main.c:216:29: error: use of undeclared identifier 'indexNewSensor'
indexNewSensor++;
^
3 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:196: recipe for target 'build/default/production/main.p1' failed
make[2]: Leaving directory 'D:/Projet_vigne/vigne_last'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/Projet_vigne/vigne_last'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 859ms)

GSM_available((、send_command_AT_ART((是函数OF COURSE,已经在另一个文件中定义(这毫无意义,因为过去执行的测试表明这两个函数工作得很好(。

不能在标签后立即进行声明,其中包括case标签。

您可以通过将相关代码放入代码块中来解决此问题:

case 1:
{   
int indexNewSensor=0;
for(int i = y+3;i<strlen(answer);i++){
//The adress is for now received as a string
strcpy(newSensorAdress[indexNewSensor],answer[i]);
indexNewSensor++;
}
}
break;

相关内容

  • 没有找到相关文章

最新更新