워닝문제, 세그멘트결함문제
고독
질문 제목 : 워닝문제, 세그멘트결함문제 (문자열을 숫자로 바꿔주는 프로그램)첫번째 소스에서 2개의 워닝이 있어서, 두번째 소스로 바꿨습니다. ( subr 함수 선언과 리턴값오류)
그런데 두번째소스 컴파일오류 없지만 실행하면 오류가 뜨는데(세그멘트결함)
어디가 잘못됬는지 못찾겠어요질문 내용 :
#include stdio.h
#include ctype.h
char buf[20] = 123456abcd;
int main(void)
{
char *p;
p = 0; /* p = buf */
subr(p);
printf(%s\n, p);
}
int subr(char *str)
{
int c;
while( *str != 0 ) {
c = *str;
if( isupper(c) ) *str = tolower(c);
str++;
}
}
////////////////////////////////////////////////////#include stdio.h
#include ctype.h
char buf[20] = 123456abcd;
void subr(char *);
int main(void)
{
char *p;
p = 0; /* p = buf */
subr(p);
printf(%s\n, p);
}voidsubr(char *str)
{
int c;
while( *str != 0 ) {
c = *str;
if( isupper(c) ) *str = tolower(c);
str++;
}
}
-
2gether
char buf[20] = {0,};
char *p;
p = buf;
strcpy(p, \123456ABCD\);