나는 포인터와 문자열을 실험하고있다. 다음 코드에서는 모든 것이 테스트되고 (컴파일하고 실행할 수 있음), strcmp를 사용할 때 충돌이 계속됩니다. 코드는 코드 블록에서 경고없이 실행됩니다. 제 실수를 지적 해 주실 수 있습니까?strcmp-crash와 문자열 비교
#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++;
}
}
'fflush (stdin);'은 정의되지 않은 동작입니다. – chris
이것은 디버거를 사용하는 방법을 배우는 시간처럼 들립니다 ... –
이것은 반드시 문제를 풀지는 않지만 v [6], c [6] 및 v [5] = c [5] = '\ 0 '; 필요합니다. –