You're saying you have this:

char array[20]; char string[100];
array[0]='1'; 
array[1]='7'; 
array[2]='8'; 
array[3]='.'; 
array[4]='9';

And you'd like to have this:

string[0]= "178.9"; // where it was stored 178.9 ....in position [0]

You can't have that. A char holds 1 character. That's it. A "string" in C is an array of characters followed by a sentinel character (NULL terminator).

Now if you want to copy the first x characters out of array to string you can do that with memcpy():

memcpy(string, array, x);
string[x] = '\0'; 
Answer from Mike on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › convert-string-to-char-array-c-plus-plus
Convert String to Char Array and Char Array to String in C++ | DigitalOcean
August 3, 2022 - C++ c_str() function along with C++ String strcpy() function can be used to convert a string to char array easily.
🌐
Reddit
reddit.com › r/cs50 › how do i convert a string to an array of chars in c?
r/cs50 on Reddit: How do I convert a string to an array of chars in C?
March 21, 2023 -

I know that a string is already technically an array of chars, but when I try to use toupper(string), it doesn’t work because toupper is designed to capitalize chars and not strings, per the documentation. I’ve been making it overly complicated and it’s stressing me out. So to start, I created an “int N=strlen(string);”, then created an array that’s “char upper[N];”. Then I write a for loop written as(please forgive the terrible syntax I’m about to write), “for (int i = 0; i < N; i++) { toupper(upper[j]); }”. What am I doing wrong?

🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_array_of_strings.htm
Array of Strings in C
Note: Here, lang[ ] is an array of pointers of individual strings. We can use a for loop as follows to print the array of strings −
🌐
Scaler
scaler.com › home › topics › what is an array of strings in c?
What is an Array of Strings in C? - Scaler Topics
April 30, 2024 - The string is a one-dimensional array of characters terminated with the null character. Since strings are arrays of characters, the array of strings will evolve into a two-dimensional array of characters. It is possible to define an array of strings in various ways, but generally, we can do ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-convert-a-string-to-a-char-array-in-c
How to Convert a String to a Char Array in C? - GeeksforGeeks
July 23, 2025 - The most straightforward method to convert a string to a char array is by using strcpy() function.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c language › array-of-strings-in-c
Array of Strings in C - GeeksforGeeks
July 23, 2025 - We can't directly change or assign the values to an array of strings in C.
🌐
Swift Forums
forums.swift.org › using swift
Create C String Array from Swift - Using Swift - Swift Forums
November 26, 2019 - Ok quick backstory, I am using vulkan with swift and ran into an issue passing an array of strings from swift into the struct VkInstanceCreateInfo. So I got a stupid question about how to create a pointer to an array of enabledLayerCount null-terminated UTF-8 strings.
🌐
WsCube Tech
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
3 days ago - Learn how to create and use an array of strings in C programming tutorial. Explore different methods and operations with examples, output, and explanations.
🌐
Quora
quora.com › How-do-you-read-a-string-into-an-array-using-scanf-in-the-C-programming-language
How to read a string into an array using scanf in the C programming language - Quora
... C language has char datatype which can be used to store a character. So array of char can be used to store a string and 2D array of char can be used to declare array of strings in C.
🌐
Unstop
unstop.com › home › blog › string array in c | a complete explanation (+code examples)
String Array In C | A Complete Explanation (+Code Examples)
March 19, 2024 - Here, the smaller box represents an array of characters (character blocks), i.e., strings, and the big box represents an array of strings. In this article, we will elaborate on how to declare and initialize a string array in C, its implementation, string functions and their uses, and more with the help of proper examples.
🌐
Quora
quora.com › Can-we-assign-a-string-to-a-char-array-in-C
Can we assign a string to a char array in C? - Quora
Answer (1 of 8): You can do that in any language — take each character in the string and assign it to the next index in an array [character]. But don’t learn programming with C. It is a primitive, old, and flawed language and you will learn a lot of unimportant things and completely miss ...
Top answer
1 of 15
305

If you don't want to change the strings, then you could simply do

const char *a[2];
a[0] = "blah";
a[1] = "hmm";

When you do it like this you will allocate an array of two pointers to const char. These pointers will then be set to the addresses of the static strings "blah" and "hmm".

If you do want to be able to change the actual string content, the you have to do something like

char a[2][14];
strcpy(a[0], "blah");
strcpy(a[1], "hmm");

This will allocate two consecutive arrays of 14 chars each, after which the content of the static strings will be copied into them.

2 of 15
251

There are several ways to create an array of strings in C. If all the strings are going to be the same length (or at least have the same maximum length), you simply declare a 2-d array of char and assign as necessary:

char strs[NUMBER_OF_STRINGS][STRING_LENGTH+1];
...
strcpy(strs[0], aString); // where aString is either an array or pointer to char
strcpy(strs[1], "foo");

You can add a list of initializers as well:

char strs[NUMBER_OF_STRINGS][STRING_LENGTH+1] = {"foo", "bar", "bletch", ...};

This assumes the size and number of strings in the initializer match up with your array dimensions. In this case, the contents of each string literal (which is itself a zero-terminated array of char) are copied to the memory allocated to strs. The problem with this approach is the possibility of internal fragmentation; if you have 99 strings that are 5 characters or less, but 1 string that's 20 characters long, 99 strings are going to have at least 15 unused characters; that's a waste of space.

Instead of using a 2-d array of char, you can store a 1-d array of pointers to char:

char *strs[NUMBER_OF_STRINGS];

Note that in this case, you've only allocated memory to hold the pointers to the strings; the memory for the strings themselves must be allocated elsewhere (either as static arrays or by using malloc() or calloc()). You can use the initializer list like the earlier example:

char *strs[NUMBER_OF_STRINGS] = {"foo", "bar", "bletch", ...};

Instead of copying the contents of the string constants, you're simply storing the pointers to them. Note that string constants may not be writable; you can reassign the pointer, like so:

strs[i] = "bar";
strs[i] = "foo"; 

But you may not be able to change the string's contents; i.e.,

strs[i] = "bar";
strcpy(strs[i], "foo");

may not be allowed.

You can use malloc() to dynamically allocate the buffer for each string and copy to that buffer:

strs[i] = malloc(strlen("foo") + 1);
strcpy(strs[i], "foo");

BTW,

char (*a[2])[14];

Declares a as a 2-element array of pointers to 14-element arrays of char.

🌐
LabEx
labex.io › questions › how-to-declare-an-array-of-strings-in-c-136081
How to Declare an Array of Strings in C | LabEx
July 25, 2024 - This mind map illustrates the key steps involved in declaring and working with an array of strings in C. The steps include the syntax for the declaration, assigning strings to the array elements, initializing the array with string literals, and properly managing the memory allocated for the strings.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
3 weeks ago - char str[] = "Geeks"; This line declares a character array str and initializes it with the string "Geeks". Internally, this creates an array like: { 'G', 'e', 'e', 'k', 's', '\0'} The null character '\0' is automatically added at the end to ...
🌐
Studytonight
studytonight.com › c › string-and-character-array.php
String and Character Arrays in C Language | Studytonight
September 17, 2024 - Learn how to create a string, character arrays in C, string input and output and string functions in C.