现在的位置: 首页 > 综合 > 正文

cannot convert from ‘unsigned char [3000]‘ to ‘char *’

2013年07月04日 ⁄ 综合 ⁄ 共 689字 ⁄ 字号 评论关闭
#include <stdio.h>

int main(void) 
{ 
    int nRead=0;
    FILE *fp_in = NULL;
	FILE *fp_out = NULL;
	char *ptr=NULL;
	unsigned char DataBuffer[3000] = {0};
	ptr=DataBuffer;
    fp_in=fopen("video-H264-1","rb");
	fp_out=fopen("video-out","wb");
    do 
	{
		if((nRead = fread(DataBuffer,sizeof(char),3000,fp_in))!=3000)break;
		fwrite(ptr,3000,1,fp_out);
	} while (nRead>0);
	return 0;
}

--------------------Configuration: test - Win32 Debug--------------------
Compiling...
2.cpp
E:\workspace\test\2.cpp(10) : error C2440: '=' : cannot convert from 'unsigned char [3000]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.

test.exe - 1 error(s), 0 warning(s)

出这样的错误,后来才知道unsigned char数组名不能直接赋给指针,得加上(char *)强制转换

 

 

抱歉!评论已关闭.