How to Convert a String to a Char Array in C? Last Updated : 05 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C, the only difference between the string and a character array is possibly the null character '\0' but strings can also be declared as character pointer in which case, its characters are immutable. In this article, we will learn how to convert a string to a char array in C.The most straightforward method to convert a string to a char array is by using strcpy() function. Let's take a look at an example: C #include <stdio.h> #include <string.h> int main() { char *s = "Hello"; char arr[20]; // Convert the string to a char array strcpy(arr, s); printf("%s", arr); return 0; } OutputHelloExplanation: The strcpy() function, copies the contents of a source string into a destination character array. This function automatically handles the copying of characters, including the null terminator ('\0'), ensuring the string is properly converted into a char array.There are also one other methods in C to convert a string to a char array.Manually Using LoopInstead of using built-in functions, each character from the string can be manually copied into a character array using a loop including the null character. C #include <stdio.h> void convert(char *s, char *arr) { while (*arr++ = *s++); } int main() { char s[] = "Hello"; char arr[20]; // Convert the string to a char array convert(s, arr); printf("%s", arr); return 0; } OutputHello Comment More infoAdvertise with us Next Article How to Create a Dynamic Array of Strings in C? H heysaiyad Follow Improve Article Tags : C Programs C Language c-array C-String C Examples +1 More Similar Reads How to Append a Character to a String in C? In this article, we will learn how to append a character to a string using the C program.The most straightforward method to append a character to a string is by using a loop traverse to the end of the string and append the new character manually.C#include <stdio.h> void addChar(char *s, char c 3 min read How to Convert an Integer to a String in C? In C, integers can be represented as strings with each digit represented by corresponding numeric character. In this article, we will learn how to convert integers into the stringExamplesInput: 1234Output: "1234"Explanation: The integer 1234 is converted to the string "1234".Input: -567Output: "-567 3 min read Convert a Char Array to Double in C Converting a char array to a double is a common operation in C programming. It involves taking a string of characters that represent a numerical value and converting it to a double-precision floating-point value. This can be done by using various approaches listed below: Convert char array into doub 4 min read How to Create a Dynamic Array of Strings in C? In C, dynamic arrays are essential for handling data structures whose size changes dynamically during the program's runtime. Strings are arrays of characters terminated by the null character '\0'. A dynamic array of strings will ensure to change it's size dynamically during the runtime of the progra 3 min read How to Split a String by a Delimiter in C? Splitting a string by a delimiter is a common task in programming. In C, strings are arrays of characters, and there are several ways to split them based on a delimiter. In this article, we will explore different methods to split a string by a delimiter in C. Splitting Strings in CThe strtok() metho 2 min read Find the Length of Character Array in C In C, a character array is a collection of elements of the âcharâ data type that are placed in contiguous memory locations and are often used to store strings. The length of a character array is defined as the total number of characters present in the array, excluding the null character ('\0') at th 2 min read Like