2017. 6. 14. 11:54
문자열 거꾸로 만드는 코드입니다.
그냥...단순하게 문자열 사이즈 반띵해서 앞뒤로 바꿔주면 끝.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
char str[9] = "abcdefgh"; | |
char str2[9] = ""; | |
int length = strlen(str); | |
for (int i = 0; i < length; i++) { | |
str2[i] = str[length - i - 1]; | |
//if (i % 2 == 1) { | |
// str2[i] = str[length - i]; | |
//} | |
//else { | |
// str2[i] = str[i]; | |
//} | |
} | |
cout << "str1 : " << str << endl; | |
cout << "str2 : " << str2 << endl; | |
return 0; | |
} |
'Programming > C++' 카테고리의 다른 글
[C++]Console Bingo(빙고) (1) | 2017.06.14 |
---|---|
[C++]주민등록번호 생성기 (0) | 2017.06.14 |
[C++]간단한 strlen, strcmp, strcat, strcpy, strtok (0) | 2017.06.14 |
[C++]간단한 야구 게임 (0) | 2017.06.14 |
[C++]중복 값 없이 랜덤으로 숫자 뽑아내기 (1) | 2017.06.13 |