Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Interface
- 상수변수
- 반복문
- Thread
- c#
- cocos2d
- 동기화블럭
- db
- C/C++
- 문자열
- 예외던지기
- 입출력
- java
- 프로그래밍
- Exception
- interface상속
- 데이터타입
- cocos2dx
- c++게임엔진
- unity
- Class함수
- singleton
- oracle
- Stack
- 데이터베이스
- 예외처리
- c++
- cocos2d-x
- 게임엔진
- 스레드
Archives
- Today
- Total
초보 프로그램 개발자
22.04.30 대소문자 변환 및 구별 법 본문
대소문자 구별을 하기위해 if문과 for문으로 문자열의 첫번째부터 마지막까지 비교하여
하나씩 변환하는 방법을 배웠었는데
strlwr,strupr 이라는 함수를 배운후 엄청 편해졌다.
ex) c++ 에서는 _를 넣어줘야한다. _strlwr, _strupr
#define _CRT_SECURE_NO_WARNINGS // scanf를 사용하기 위함
#include <cstdio>
#include <cstring>
void main() {
char new_id[15];
int count = 0;
int input;
printf("대문자로 바꾸려면 1\n");
printf("소문자로 바꾸려면 2\n");
fseek(stdin, 0, SEEK_END);
scanf("%d", &input);
printf("메뉴를 선택해주세요: ");
printf("문자열을 입력해주세요 :");
fseek(stdin, 0, SEEK_END);
scanf("%s", new_id);
while(new_id[count]) {
if (input == 1) {
_strupr(new_id); //cstring에 들어가있는 함수 소문자를 대문자로 변환
}
else if (input == 2) {
_strlwr(new_id); //cstring에 들어가있는 함수 대문자를 소문자로 변환
}
count++;
}
printf("%s", new_id);
}
문자열이 대문자인지 소문자인지 비교해주는 함수인
isupper, islower 이라는 함수도 있다.
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cctype> // isupper, islower 함수를 사용하기위함
void main() {
char new_id[10];
int count = 0;
printf("문자열을 입력해주세요 :");
fseek(stdin, 0, SEEK_END);
scanf("%s", new_id);
while (new_id[count]) {
if (isupper(new_id[count])) { // count번째 문자가 대문자인지 비교
printf( "%d 번째 문자는 대문자 입니다.\n", count);
}
else if (islower(new_id[count])) { // count번째 문자가 소문자인지 비교
printf("%d 번째은 문자는 소문자 입니다.\n", count);
}
count++;
}
}
isupper, islower 함수와 strlwr, strupr 함수를 같이 사용하고 싶었으나, 아직 내 실력이 많이 부족하여
더 공부를 해봐야 할것 같다.
'C C++' 카테고리의 다른 글
#define과 #define매크로함수 만들기 (0) | 2022.08.25 |
---|---|
회원 가입 아이디 만들기 (0) | 2022.05.10 |