我比較字符串的兩個數組,但程序比較一些字符串後異常終止:比較字符串時,下面的程序異常終止?
什麼是錯我的代碼?
int main()
{
int N,Q;
printf("Enter no. of strings:");
scanf("%d",&N);
char *a[N],*b[Q],k[50],*p;
int len;
//scanning first array of strings
for(int i=0;i<N;i++)
{
scanf("%s",k);
len=strlen(k);
p=(char*)malloc((len+1)*sizeof(char));
strcpy(p,k);
a[i]=p;
}
printf("no. of Query:");
scanf("%d",&Q);
//scanning second array of strings
for(int i=0;i<Q;i++)
{
scanf("%s",k);
len=strlen(k);
p=(char*)malloc((len+1)*sizeof(char));
strcpy(p,k);
b[i]=p;
}
***//comparing both the arrays of strings***
for(int i=0;i<Q;i++)
{
for(int j=0;j<N;j++)
{
int i=strcmp(a[j],b[i]);
printf("%d\t",i);
}
printf("\n");
}
return 0;
}
爲什麼這麼多問號? 。 –
'字符* B [Q];'必須的scanf( 「%d」 之後','&Q);我 – BLUEPIXY
輸出attched圖像 –