C++
[C++] memset, isupper/islower
dh_0e
2025. 2. 13. 01:14
memset
- 메모리의 특정 영역을 지정된 값으로 초기화하는 함수
- 주로 배열이나 구조체의 초기화에 사용
- <cstring> 헤더에 포함
#include <iostream>
#include <cstring>
int main() {
char str[50] = "Hello, world!";
printf("Before memset: %s\n", str); // Before memset: Hello, world!
// str 7번째 값부터 5개의 바이트를 'X'로 설정
memset(str + 7, 'X', 5);
printf("After memset: %s\n", str); // After memset: Hello, xxxxx!
return 0;
}
isupper / islower
- 문자가 대문자인지 소문자인지 여부를 판별하는 함수
- <cctype> 헤더에 포함
#include <iostream>
#include <cctype>
int main() {
char ch = 'A', ch1 = 'a';
if (isupper(ch)) {
printf("%c는 대문자입니다.\n", ch);
}
if (islower(ch1)) {
printf("%c는 소문자입니다.\n", ch);
}
return 0;
}