반말 존대말로 바꾸기
글쓴이: babbab / 작성시간: 금, 2011/02/18 - 8:51오전
간단한 반말 존대말로 바꾸기 프로그램을 짤려하는데
getline후 "이다"를 치면 mainstr의 길이가 자꾸 5로 됩니다.
wcslen(mainstr)은 5로나오고
wcslen("이다")는 2로 나옵니다.
같은 스트링 길이에 왜 wcslen이 두 다른 결과를 나타내는지 이유를 알고 계신분께 묻습니다.
#include <stdio.h>
#include <wchar.h>
int findatrear(wchar_t [], wchar_t []);
void replace(wchar_t [], wchar_t []);
int getline(wchar_t [], int);
main(){
wchar_t mainstr[1000];
printf("%d", getline(mainstr, 1000));
#if 0
while (getline(mainstr, 1000) > 0)
{
printf("%d", wcslen(mainstr));
if (findatrear(mainstr, L"이다\n"))
replace(mainstr, L"입니다\n");
else if (findatrear(mainstr, L"한다\n"))
replace(mainstr, L"합니다\n");
else if (findatrear(mainstr, L"된다\n"))
replace(mainstr, L"됩니다\n");
wprintf(L"%s", mainstr);
}
#endif
}
int findatrear(wchar_t str[], wchar_t strtofind[])
{
int i = wcslen(str);
if (wcscmp(str[i-3], strtofind) == 0)
return 1;
return 0;
}
void replace(wchar_t str[], wchar_t strtoreplace[])
{
int i = wcslen(str);
str[i-3] = L'\0';
wcscat(str, strtoreplace);
}
int getline(wchar_t str[], int max)
{
fgetws(str,max,stdin);
return wcslen(str);
}Forums:


댓글 달기