How to convert a string into an array in C language?

In C language, a string is essentially a character array. Therefore, you can directly assign a string to a character array to turn the string into an array.

The following is an example code:

#include <stdio.h>

int main() {
    char str[] = "Hello";  // 字符串赋值给字符数组

    // 遍历字符数组并打印每个字符
    for (int i = 0; i < sizeof(str)/sizeof(char); i++) {
        printf("%c\n", str[i]);
    }

    return 0;
}

In the example above, the string “Hello” is assigned to the character array str. By iterating through the character array, each character can be printed one by one. The output result is:

H
e
l
l
o
bannerAds