wcslen function

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.
 
N

Nobody

i typed 2 korean characters and it spits out 5 as length of
the string. anyone knows why?

setlocale(LC_CTYPE, ...) ?

According to the standard, programs are supposed to start in the "C"
locale.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top