我如何才能 运行 为 const char* 中的每个字符编码?

How would I be able to run code for each character in a const char*?

我正在用 C 为我正在制作的自定义操作系统编写内核,我想知道如何循环 const char* 中的每个字符,然后使用 if 运算符来识别 const char* 到 运行 特定代码中的一个字符。

how I could loop for every character in a const char*

像那样:

const char *p;
for (p = str; *p; p++) {
    // ...
}

and then use if operators to identify a character in the const char* to run specific code.

在你的循环中:

if (*p == 'x') { // Identify a character
    // Run the specific code here
}

或者,如果你想识别很多字符:

switch (*p) {
case 'x':
    // Run the specific code here
    break;

case 'y':
    // Run the specific code here
    break;

// ...
}