小编Tho*_*den的帖子

逐个字符访问外语字符串

我知道这个问题可能非常基础.如果这是显而易见的事,请原谅我.考虑以下程序:

#include <stdio.h>

int main(void) {
   // this is a string in English
   char * str_1 = "This is a string.";
   // this is a string in Russian
   char * str_2 = "??? ????????? ?????????.";
   // iterator
   int i;
   // print English string as a string
   printf("%s\n", str_1);
   // print English string byte by byte
   for(i = 0; str_1[i] != '\0'; i++) {
      printf(" %c  ",(char) str_1[i]);
   }
   printf("\n");
   // print numerical values of English string byte by byte
   for(i …
Run Code Online (Sandbox Code Playgroud)

c string unicode-string

9
推荐指数
1
解决办法
325
查看次数

普通计算机是否使用大端编码?

我理解大端和小端。然而,我可以访问的所有计算机(AMD、Intel、Broadcom)的所有处理器都是小端字节序。这让我想知道是否有任何常见的计算机使用大端字节序。谁能提供例子吗?

processor cpu-architecture endianness

6
推荐指数
1
解决办法
7567
查看次数

在 C 中排序时无法让 strcoll() 使用区域设置

我无法让与语言环境相关的函数(例如 strcoll())在 C 中工作。我想知道我是否做错了什么和/或如何让它工作。以下是本书中的示例程序:Prinz、Peter 和 Tony Crawford。2016 年。《C 简而言之》,第二版,第 14 页。574. 北京-波士顿-法纳姆-塞瓦斯托波尔-东京:奥莱利。ISBN-13:978-1-491-90475-6。

#include <stdio.h>
#include <string.h>
#include <locale.h>

int main(void) {
   char *samples[ ] = { "curso", "churro" };
   setlocale(LC_COLLATE, "es_ES.UTF-8");
   int result = strcoll(samples[0], samples[1]);
   if(result == 0) {
      printf("The strings \"%s\" and \"%s\" are "
             "alphabetically equivalent.\n",
             samples[0], samples[1]);
   } else if(result < 0) {
      printf("The string \"%s\" comes before \"%s\" "
             "alphabetically.\n",
             samples[0], samples[1]);
   } else if(result > 0) {
      printf("The string \"%s\" comes after \"%s\" " …
Run Code Online (Sandbox Code Playgroud)

c locale collation

5
推荐指数
1
解决办法
154
查看次数