错误C2143和错误C2065 [英] error C2143 and error C2065

查看:79
本文介绍了错误C2143和错误C2065的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <Windows.h>
//#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
//#include <delay.h>
//#include <system.h>
//#include "/usr/include/linux/i2c.h"
#define BOOT_CODE "00 01 8a eb"
#define USER_CODE "00 00 00 58"

#define BOOT_MODE	0x00
#define USER_MODE	0x01
#define OTHER_MODE	0x02

#define bool int
#define true 1
#define false 0

typedef struct HEX_FILE_LINE_STRUCT
{
        uint8_t iDataLenght;//8byte
        uint8_t  iType;//8 byte
        uint8_t  iBuff[128];//8byte*255
        uint8_t iCrcByte;//crc
//	int16_t iStartAddress;//16 byte
     //   int32_t iLineByteNum;//32 byte
}StructHexFile;

StructHexFile gHexLineData;
uint16_t iStartAddress;
uint32_t iLineByteNum;
char cFlashData[512];

int ReadDeviceRunMode(char cBuff[]);


int ReadDeviceRunMode(char cBuff[])
{
	int iRunMode=OTHER_MODE;
//	char cRecvBuff[512];
	FILE *pfile = _popen(cBuff,"r");
        if( !pfile )
        {
                printf("open popen failed!\r\n");
                printf("read the PSU's device code failed!,stop update!\r\n");
                return iRunMode;
        }

        printf("read device code of the psu!\r\n");
        char cRecvBuff[512];
        while(fgets(cRecvBuff,sizeof(cRecvBuff),pfile))
        {
			
        }
        _pclose(pfile);

	
	if ( ( cRecvBuff[1] == '0' ) && ( cRecvBuff[2] == '0' ) &&
             ( cRecvBuff[4] == '0' ) && ( cRecvBuff[5] == '0' )&&
             ( cRecvBuff[7] == '0' ) && ( cRecvBuff[8] == '0' )&&
             ( cRecvBuff[10] == '5' ) && ( cRecvBuff[11] == '8' ) )
        {
                printf("the psu in user mode!\r\n");
                iRunMode = USER_MODE;
        }else if( ( cRecvBuff[1] == '0' ) && ( cRecvBuff[2] == '0' ) &&
                  ( cRecvBuff[4] == '0' ) && ( cRecvBuff[5] == '1' ) &&
                  ( cRecvBuff[7] == '8' ) && ( cRecvBuff[8] == 'a' ) &&
                  ( cRecvBuff[10] == 'e' ) && ( cRecvBuff[11] == 'b' ) )
        {
                printf("the psu in boot mode!\r\n");
                iRunMode = BOOT_MODE;
        }else{
                printf("read psu's device code error,stop update!\r\n");
                iRunMode = OTHER_MODE;
        }
	return iRunMode;
}


void usleep(__int64 usec) 
{ 
    HANDLE timer; 
    LARGE_INTEGER ft; 

    ft.QuadPart = -(10*usec); // Convert to 100 nanosecond interval, negative value indicates relative time

    timer = CreateWaitableTimer(NULL, TRUE, NULL); 
    SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 
    WaitForSingleObject(timer, INFINITE); 
    CloseHandle(timer); 
}


//argv[1]:ipmitool path:/usr/local/bin/ipmitool
//argv[2]:psu address
//argv[3]:hex path
int main(char argc,char* argv[])
{
	int i = 0;
	char cCmdLine[512];
	int iFlagRunMode = OTHER_MODE;
	if ( 4 > argc )
	{
		printf("no parements,stop update!\r\n");
		return 0xFF;
	}
	printf("start update...\r\n");


	sprintf(cCmdLine,"%s raw 0x06 0x52 0x0b %s 0x04 0xD0",argv[1],argv[2]);

//read device run mode
	if ( USER_MODE == ReadDeviceRunMode(cCmdLine)  )
	{
		printf("write ISP Key!\r\n");
		printf("go to boot mode\r\n");
//write device isp key		
		sprintf(cCmdLine,"%s raw 0x06 0x52 0x0b %s 0x00 0xD1 0x49 0x6E 0x73 0x72",argv[1],argv[2]);			

		usleep(1000*250);//250ms
	}
//	delay(2);//2*4ms
//go to boot mode

	printf("go to user mode successful!\r\n");
	printf("update successful!\r\n");	
	printf("stop update!\r\n");
	return 0x00;	
}




当我编译C使用VS2012 C ++时,它总是在行显示错误C2143 54,错误C2065在第55行。但如果我在FILE * pfile = _popen(cBuff,"r")之前重新定义了char cRecvBuff [512],那就行了,没有错误显示。可以
任何人都可以帮助我吗?抱歉,我是C节目的全体新人。

when i compile the C use the VS2012 C++, it always shows the error C2143 at line 54,and error C2065 at line 55. but if i redefine the  char cRecvBuff[512] before the FILE *pfile = _popen(cBuff,"r"), that's works and no error shows. can anybody can help me? sorry i am total fresh man to the C programme.

推荐答案

在12/10/2017 10:29 PM,Leo0on写道:

On 12/10/2017 10:29 PM, Leo0on wrote:


当我编译C使用VS2012 C ++时,它总是在第54行显示错误C2143,在第55行显示错误C2065。但是如果我重新定义了char在FILE * pfile = _popen(cBuff," r")之前的cRecvBuff [512],这是有效的,没有错误显示。

when i compile the C use the VS2012 C++, it always shows the error C2143 at line 54,and error C2065 at line 55. but if i redefine the  char cRecvBuff[512] before the FILE *pfile = _popen(cBuff,"r"), that's works and no error shows.

在C中(不像C ++),所有变量都必须在任何语句之前在块的开头声明。

In C (unlike C++), all variables have to be declared at the beginning of a block, before any statements.


这篇关于错误C2143和错误C2065的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆