-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
strcat 질문드립니다.
22.08.06 23:18 작성 조회수 134
0
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char source[] = "Copy this!";
char dest[50];
strcpy_s(dest, source);
cout << source << endl;
cout << dest << endl;
strcat_s(dest, dest);
cout << dest << endl;
cout << source << endl;
return 0;
}
strcat_s(dest, dest)를 해도 Copy this!Copy this! 로 잘 나올지 궁금해서 실행해 봤는데, 런타임 에러가 떴습니다.
buffer is too small이란 에러가 무엇을 뜻하나요?
메모리 공간이 부족하다는 건가 싶었는데, dest의 최대 크기가 50이므로 부족할 이유도 딱히 없는 것 같고 런타임 에러의 원인이 궁금합니다.
답변을 작성해보세요.
0
강민철
2022.08.08
strcpy_s와 strcat_s의 인자를 적절하게 사용하신 것이 맞나요?
두 함수는 (strcpy와 strcat와는 다르게)
기본적으로 세 개의 인자를 받습니다.
아래 링크를 참고 바랍니다.
https://en.cppreference.com/w/c/string/byte/strcpy
https://en.cppreference.com/w/c/string/byte/strcat
답변 1