在vc上运行时出现了Access Violation的错误。
我用c编了一个条形码识别的程序,但是在vc上运行时,刚用scanf输完13个字符后就出现了unhandled exception in EAN13.exe:0xC0000005:Access Violation的错误,请教一下是哪里出错了?下面是我的程序。 #include <string.h>
#include <stdio.h>
main()
{
int j,k,sum=0;
unsigned int i;
char *str,(*p)[7],num[14];
char dataA[10][7]={{'0','0','0','1','1','0','1'},{'0','0','1','1','0','0','1'},{'0','0','1','0','0','1','1'},
{'0','1','1','1','1','0','1'},{'0','1','0','0','0','1','1'},{'0','1','1','0','0','0','1'},
{'0','1','0','1','1','1','1'},{'0','1','1','0','1','1','1'},{'0','1','1','1','0','1','1'},
{'0','0','0','1','0','1','1'}};
char dataB[10][7]={{'0','1','0','0','1','1','1'},{'0','1','1','0','0','1','1'},{'0','0','1','1','0','1','1'},
{'0','1','0','0','0','0','1'},{'0','0','1','1','1','0','1'},{'0','1','1','1','0','0','1'},
{'0','0','0','0','1','0','1'},{'0','0','1','0','0','0','1'},{'0','0','0','1','0','0','1'},
{'0','0','1','0','1','1','1'}};
char dataC[10][7]={{'1','1','1','0','0','1','0'},{'1','1','0','0','1','1','0'},{'1','1','0','1','1','0','0'},
{'1','0','0','0','0','1','0'},{'1','0','1','1','1','0','0'},{'1','0','0','1','1','1','0'},
{'1','0','1','0','0','0','0'},{'1','0','0','0','1','0','0'},{'1','0','0','1','0','0','0'},
{'1','1','1','0','1','0','0'}};
char dataAB[10][6]={{'A','A','A','A','A','A'},{'A','A','B','A','B','B'},{'A','A','B','B','A','B'},
{'A','A','B','B','B','A'},{'A','B','A','A','B','B'},{'A','B','B','A','A','B'},
{'A','B','B','B','A','A'},{'A','B','A','B','A','B'},{'A','B','A','B','B','A'},
{'A','B','B','A','B','A'}};
do
{
printf("input 13 numbers:"); /*input bar code*/
for (i=1;i<14;i++)
scanf("%c",&num[i]);
for(i=2;i<13;i+=2) /*parity bit inspect*/
sum=sum+num[i]-48;
/*num[i]-48: string0=number0+48 (ascii) */
sum=sum*3;
for(i=1;i<13;i+=2)
sum=sum+num[i]-48;
k=10-sum%10;
if (k!=num[13]-48) printf("there is an error in parity bit!\n");
}
while(k!=num[13]-48);
str= "000000000101"; /*paint bar code*/
for(i=2;i<=7;i++)
{
for(j=0;j<6;j++)
{
if(dataAB[num[1]-48-1][j]=='A') p=dataA;
else p=dataB;
for(k=0;k<7;k++)
{
strcat (str,*(p+num[i]-48-1)+k);
}
}
}
strcat (str,"01010");
for(i=8;i<=13;i++)
{
for(j=0;j<6;j++)
{
p=dataC;
for(k=0;k<7;k++)
{
strcat (str,*(p+num[i]-48-1)+k);
}
}
}
strcat (str,"101000000000");
for(i=0;i<= strlen(str);i++) /*print bar code*/
{
if(str[i]=='1') printf("|");
else printf(" ");
}
printf("\n");
}