O
Owner
anyone know well with wcslen function?
#include <stdio.h>
#include <wchar.h>
int getline(wchar_t [], int);
main(){
wchar_t str[100];
/*fgetws(str,100,stdin);*/
getline(str,100);
printf("%d", wcslen(str));
wprintf(L"%s", str);
}
int getline(wchar_t s[], int lim){
int c,i;
for (i=0; i<lim-1 && (c=getwchar())!=EOF && c!=L'\n'; ++i)
s = c;
if (c == L'\n') {
s = c;
++i;
}
s = L'\0';
return i;
}
c:\Users\Owner\Desktop>cl test.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.c
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
c:\Users\Owner\Desktop>test
ÀÌ´Ù
5ÀÌ´Ù
i typed 2 korean characters and it spits out 5 as length of
the string. anyone knows why? i'm expecting 3 as length
including \n character.
#include <stdio.h>
#include <wchar.h>
int getline(wchar_t [], int);
main(){
wchar_t str[100];
/*fgetws(str,100,stdin);*/
getline(str,100);
printf("%d", wcslen(str));
wprintf(L"%s", str);
}
int getline(wchar_t s[], int lim){
int c,i;
for (i=0; i<lim-1 && (c=getwchar())!=EOF && c!=L'\n'; ++i)
s = c;
if (c == L'\n') {
s = c;
++i;
}
s = L'\0';
return i;
}
c:\Users\Owner\Desktop>cl test.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.c
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
c:\Users\Owner\Desktop>test
ÀÌ´Ù
5ÀÌ´Ù
i typed 2 korean characters and it spits out 5 as length of
the string. anyone knows why? i'm expecting 3 as length
including \n character.