그래서 scanf 부분을 주석 처리하고 (그리고 내 자신의 문자열로 초기화했습니다.) scanf를 사용하면 왜 충돌이 발생합니까? 나는 scanf()에 넣은 실제 인자를 믿는다; 맞습니다. 당신이 버퍼에 scanf()
포인터를 보내는 것을scanf ("% s", ptr)에 대한 포인터를 전달할 수 없습니다.
#include <stdio.h>
#include <stdlib.h>
int strendmilan(char *s,char *t)
{
int scntr = 0,tcntr = 0;
while(*(s+(scntr++)) != '\0')
;
--scntr;
while(*(t+(tcntr++)) != '\0')
;
--tcntr;
while(tcntr >= 0)
if(*(s+scntr--) == *(t+tcntr--))
;
else
return 0;
return 1;
}
int main()
{
char *s,*t;
/*
scanf("%s",s);
scanf("%s",t);
*/
s = "HAHAHACOOL";
t = "COOL";
if(strendmilan(s,t) == 0)
printf("NOT");
else
printf("YES");
getch();
}
'scanf '를 호출하기 전에 일부 메모리를's'에 할당하십시오. – cnicutar