我正在试验指针和字符串。在下面的代码中,所有内容都经过了测试(您可以自己编译和运行),但是当我尝试使用 strcmp 时,我一直在崩溃。代码在代码块中运行而没有警告。你能指出我导致程序崩溃的错误吗?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int choice,x=7,k,q,cmp,j=0,i=0,N;
char v[5],str[80],c[5];
char *B[11][2]=
{"-----","0",
".----","1",
"..---","2",
"...--","3",
"....-","4",
".....","5",
"-....","6",
"--...","7",
"---..","8",
"----.","9",
NULL,NULL};
printf("Give a stream");
if(gets(str)) printf("%s\n",str);
fflush(stdin);
i=0;
while(str[i])
{
q=0;
j=i+1;
while(q%5!=0)
{
v[j]=str[j];
puts(v);
j++;
q++;
}
printf("Hello");
for(k=0; k<11; k++)
{
strcpy(c,B[k][0]);
printf("%s",c);
x=strcmp(v,c);
//Problem:
printf("%d",c);
if(x==0) printf("hi");
}
i=i+1;
j++;
}
}