OPEN_scc: //Enroll Finger int counts=0; int BUFFER = 1; enroll_label: printf("Enroll Finger Test\n"); nRet = ZAZ_NO_FINGER; printf("1. Enroll: Please press finger1......\n"); while(nRet == ZAZ_NO_FINGER) { nRet=ZAZGetImage(nhanle,DEV_ADDR); counts++; if(counts > 10000000) printf("wating time over......\n"); else printf("wating time %d......\n",counts); } if(nRet != ZAZ_OK) { printf("ZAZGetImage is Fail ,errorr code = %d......\n",nRet); return 0; } printf("2. ZAZGetImage ok......\n"); //BYTE pImage[256*288]; //int nImageLen; //ZAZUpImage(DEV_ADDR,pImage,&nImageLen); //ZAZImgData2BMP(pImage,"fp.bmp"); nRet = ZAZGenChar(nhanle,DEV_ADDR,BUFFER); if(nRet != ZAZ_OK) { printf("ZAZGenChar is Fail ,errorr code = %d......\n",nRet); goto enroll_label; } printf("3. ZAZGenChar ok Buffer = %d......\n",BUFFER); BUFFER++; if(BUFFER < 3) goto enroll_label; nRet = ZAZRegModule(nhanle,DEV_ADDR); if(nRet != ZAZ_OK) { printf("ZAZRegModule is Fail ,errorr code = %d......\n",nRet); BUFFER = 1; goto enroll_label; } printf("4. ZAZRegModule ok \n"); nRet = ZAZStoreChar(nhanle,DEV_ADDR,CHAR_BUFFER_A,1); if(nRet != ZAZ_OK) { printf("ZAZStoreChar is Fail ,errorr code = %d......\n",nRet); BUFFER = 1; goto enroll_label; } printf("5. ZAZStoreChar ok id = %d\n",1); printf("END\n"); //Search Finger这段代码如何把标记替换掉,不用goto用其它方式实现
时间: 2024-01-28 09:03:36 浏览: 69
可以使用循环语句来代替goto语句,具体来说,可以使用while循环来实现。在while循环中设置一个条件,当条件满足时进行循环,否则跳出循环。在循环中对BUFFER进行操作,当BUFFER满足条件时跳出循环。下面是使用while循环实现的代码:
```
int counts=0;
int BUFFER = 1;
printf("Enroll Finger Test\n");
nRet = ZAZ_NO_FINGER;
printf("1. Enroll: Please press finger1......\n");
while(nRet == ZAZ_NO_FINGER) {
nRet=ZAZGetImage(nhanle,DEV_ADDR);
counts++;
if(counts > 10000000)
printf("wating time over......\n");
else
printf("wating time %d......\n",counts);
}
if(nRet != ZAZ_OK) {
printf("ZAZGetImage is Fail ,errorr code = %d......\n",nRet);
return 0;
}
printf("2. ZAZGetImage ok......\n");
//BYTE pImage[256*288];
//int nImageLen;
//ZAZUpImage(DEV_ADDR,pImage,&nImageLen);
//ZAZImgData2BMP(pImage,"fp.bmp");
while(BUFFER < 3) {
nRet = ZAZGenChar(nhanle,DEV_ADDR,BUFFER);
if(nRet != ZAZ_OK) {
printf("ZAZGenChar is Fail ,errorr code = %d......\n",nRet);
BUFFER = 1;
continue;
}
printf("3. ZAZGenChar ok Buffer = %d......\n",BUFFER);
BUFFER++;
}
nRet = ZAZRegModule(nhanle,DEV_ADDR);
if(nRet != ZAZ_OK) {
printf("ZAZRegModule is Fail ,errorr code = %d......\n",nRet);
BUFFER = 1;
continue;
}
printf("4. ZAZRegModule ok \n");
nRet = ZAZStoreChar(nhanle,DEV_ADDR,CHAR_BUFFER_A,1);
if(nRet != ZAZ_OK) {
printf("ZAZStoreChar is Fail ,errorr code = %d......\n",nRet);
BUFFER = 1;
continue;
}
printf("5. ZAZStoreChar ok id = %d\n",1);
printf("END\n");
```
使用while循环能够让代码更清晰易懂,避免了goto语句带来的混乱。
阅读全文