取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
Highlighted
687 次查看
注册日期: ‎06-03-2015

HLS 2018.2 2次数组打印不一致

跳至解决方案

我用HLS2018.2,定义了2维数组,并初始化。还定义了1个2维数组和3维数组,读外部文件初始化它们。第一个2维数组,2次打印出的数值不一致。

1st printf
coef[0][0]=-4
coef[0][1]=-4
coef[0][2]=-4
coef[1][0]=-4
coef[1][1]=32
coef[1][2]=-4
coef[2][0]=-4
coef[2][1]=-4
coef[2][2]=-4
2nd printf
coef[0][0]=0
coef[0][1]=0
coef[0][2]=-4
coef[1][0]=-4
coef[1][1]=32
coef[1][2]=-4
coef[2][0]=-4
coef[2][1]=-4
coef[2][2]=-4

 

用到代码见附件,主要代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ap_int.h>

typedef ap_uint<8> u8;
typedef ap_int<8> i8;

typedef ap_uint<9> u9;
typedef ap_int<9> i9;

typedef char int8;
typedef short int16;
typedef int int32;

int main()
{
int32 i,j;

const i8 coef[3][3] = {
{-4,-4,-4},
{-4,32,-4},
{-4,-4,-4}
};

int16 temp;
i9 coef1[64][5] ;
i9 coef2[4][64][5] ;
FILE *fid;


printf("1st printf\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("coef[%d][%d]=%d\n", i,j, (int8)coef[i][j]);


}



fid = fopen("coef.txt","r");
if(fid==NULL)
{
printf("open file coef.txt failed!\n");
exit(1);
}

fseek(fid,0,SEEK_SET);
for(i=0;i<64;i++)
{
for(j=0;j<5;j++)
{
fscanf(fid, "%d", &temp);
coef1[i][j] = (i9)temp;
coef2[0][i][j] = (i9)temp;
coef2[1][i][j] = (i9)temp;
coef2[2][i][j] = (i9)temp;
coef2[3][i][j] = (i9)temp;

}
}

fclose(fid);
fid=NULL;


printf("2nd printf\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("coef[%d][%d]=%d\n", i,j, (int8)coef[i][j]);


}




}

0 项奖励
1 解答

已接受的解答
Highlighted
Xilinx Employee
Xilinx Employee
637 次查看
注册日期: ‎03-24-2010

Change "fscanf(fid, "%d", &temp);" to "fscanf(fid, "%hd", &temp);".

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

在原帖中查看解决方案

3 回复数
Highlighted
Xilinx Employee
Xilinx Employee
638 次查看
注册日期: ‎03-24-2010

Change "fscanf(fid, "%d", &temp);" to "fscanf(fid, "%hd", &temp);".

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

在原帖中查看解决方案

Highlighted
599 次查看
注册日期: ‎06-03-2015

Hi Brucey,

按照您的修改,问题的确得到了解决。谢谢了

0 项奖励
Highlighted
597 次查看
注册日期: ‎06-03-2015
Hi Brucey,
按照您的修改,问题得以解决。谢谢
0 项奖励