1924번 - 2007년
#include<stdio.h>#include<string.h>int main(void){ int a,b,d,g; char e[4]; scanf("%d %d", &a, &g); if(a==1) { b=g+7; d=b%7; } else if(a==2) { b=g+10; d=b%7; } else if(a==3) { b=g+10; d=b%7; } else if(a==4) { b=g+6; d=b%7; } else if(a==5) { b=g+8; d=b%7; } else if(a==6) { b=g+11; d=b%7; } else if(a==7) { b=g+6; d=b%7; } else if(a==8) { b=g+9; d=b%7; } else if(a==9) { b=g+12; d=b%7; } else if(a==10) { b=g+7; d=b%7; } else if(a==11) { b=g+10; d=b%7; } else if(a==12) { b=g+12; d=b%7; } if(d==0) {strcpy(e,"sun");} else if(d==1) {strcpy(e,"mon");} else if(d==2) {strcpy(e,"tue");} else if(d==3) {strcpy(e,"wed");} else if(d==4) {strcpy(e,"thu");} else if(d==5) {strcpy(e,"fri");} else if(d==6) {strcpy(e,"sat");} printf("%s", e); return 0;}
계속 고치다가 답은 정상적으로 출력되는거 확인하고 질문 남겨요
왜 런타임 에러가 날까요?
//런타임 에러 문자열 크기 늘려주어 해결
근데 왜 틀렸다고 뜰까요
문자열은 null문자로 끝나야해서 e 배열 크기를 하나 더 잡아야합니다.
런타임에러 해결했는데 소문자여서 자꾸 틀렸다고 나오는거였습니다
눈뜬 장님이여서 시간버렸당ㅜ
그리고 문자열 함수 사용할 때는 #include<string.h>
string(줄,일련) 이거 꼭 해줄것 아니면 문자열 함수 사용할 수 없다고 나옴
댓글을 작성하려면 로그인해야 합니다.
difmfmdi 7년 전
#include<stdio.h>
#include<string.h>
int main(void)
{
int a,b,d,g;
char e[4];
scanf("%d %d", &a, &g);
if(a==1)
{
b=g+7;
d=b%7;
}
else if(a==2)
{
b=g+10;
d=b%7;
}
else if(a==3)
{
b=g+10;
d=b%7;
}
else if(a==4)
{
b=g+6;
d=b%7;
}
else if(a==5)
{
b=g+8;
d=b%7;
}
else if(a==6)
{
b=g+11;
d=b%7;
}
else if(a==7)
{
b=g+6;
d=b%7;
}
else if(a==8)
{
b=g+9;
d=b%7;
}
else if(a==9)
{
b=g+12;
d=b%7;
}
else if(a==10)
{
b=g+7;
d=b%7;
}
else if(a==11)
{
b=g+10;
d=b%7;
}
else if(a==12)
{
b=g+12;
d=b%7;
}
if(d==0)
{strcpy(e,"sun");}
else if(d==1)
{strcpy(e,"mon");}
else if(d==2)
{strcpy(e,"tue");}
else if(d==3)
{strcpy(e,"wed");}
else if(d==4)
{strcpy(e,"thu");}
else if(d==5)
{strcpy(e,"fri");}
else if(d==6)
{strcpy(e,"sat");}
printf("%s", e);
return 0;
}
계속 고치다가 답은 정상적으로 출력되는거 확인하고 질문 남겨요
왜 런타임 에러가 날까요?
//런타임 에러 문자열 크기 늘려주어 해결
근데 왜 틀렸다고 뜰까요