Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/String-length/C/string-length-1.c
Normal file
9
Task/String-length/C/string-length-1.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *string = "Hello, world!";
|
||||
size_t length = strlen(string);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
Task/String-length/C/string-length-2.c
Normal file
10
Task/String-length/C/string-length-2.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
int main(void)
|
||||
{
|
||||
const char *string = "Hello, world!";
|
||||
size_t length = 0;
|
||||
|
||||
const char *p = string;
|
||||
while (*p++ != '\0') length++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
Task/String-length/C/string-length-3.c
Normal file
9
Task/String-length/C/string-length-3.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char s[] = "Hello, world!";
|
||||
size_t length = sizeof s - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
Task/String-length/C/string-length-4.c
Normal file
14
Task/String-length/C/string-length-4.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
wchar_t *s = L"\x304A\x306F\x3088\x3046"; /* Japanese hiragana ohayou */
|
||||
size_t length;
|
||||
|
||||
length = wcslen(s);
|
||||
printf("Length in characters = %d\n", length);
|
||||
printf("Length in bytes = %d\n", sizeof(s) * sizeof(wchar_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
Task/String-length/C/string-length-5.c
Normal file
13
Task/String-length/C/string-length-5.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
char moose[] = "møøse";
|
||||
printf("bytes: %d\n", sizeof(moose) - 1);
|
||||
printf("chars: %d\n", (int)mbstowcs(0, moose, 0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue