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.
Discussions

How do I convert a string to an array of chars in C?
No need. string[n] IS char[n] of string. If you try to print string[n] as a char (instead of a string) you'll get that letter. You can evaluate and modify it just like that. No fuss, no muss. (For fun: You can also printf, say, char[5] of a string as a string, and it'll print everything from that letter on.) Note that the array is zero indexed, and there's an invisible null on the end of that string that doesn't get measured. So "Hello!" will return a length of 6, but is an array of char[7]. The extra char (7) holds the null. More info: Yes, a string is just an array of char. When functions like printf are told to print a string, they go to the supplied variable's address and keep printing (or otherwise acting on) the char found there until they hit a null (\0). (This is why printing a string you've manipulated can segfault.) This is ALSO why in higher level languages that allow strings to be concatenated it's considered an "expensive" thing to do - because you can't just append to the end of an array, you need to make a new one and copy everything over. More on reddit.com
๐ŸŒ r/cs50
6
3
March 21, 2023
how do I assign a string to an array in C?
char myarr[10][0]; This line is going to be a problem. It is allocating ten zero byte arrays. You can't store any data in this variable. Can you describe in English what you want to be able to do with myarr? More on reddit.com
๐ŸŒ r/learnprogramming
5
2
November 9, 2020
Store string into array in c - Stack Overflow
Sign up to request clarification or add additional context in comments. ... @alex that is the length of each string. So there is an array of 3 strings, and each string has space for 256 characters (really only 255 characters, because there is always a terminating null character (\0) at the ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Create C String Array from Swift - Using Swift - Swift Forums
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. More on forums.swift.org
๐ŸŒ forums.swift.org
0
November 26, 2019
๐ŸŒ
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 โˆ’
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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 ...
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ array of strings in c
Array of Strings in C | Delft Stack
October 12, 2023 - Each curly braced element is supposed to be stored in a consecutive memory region of length MAX_LENGTH. In case the initializer notation specifies the fewer elements than the array size, the remaining elements are implicitly initialized with \0 bytes. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LENGTH 100 #define NUM_STRINGS 10 int main() { char arr2[NUM_STRINGS][MAX_LENGTH] = {{"first string"}, {"second string"}, {"third string"}, {"fourth string"}, {"fifth string"}}; for (int i = 0; i < NUM_STRINGS; ++i) { printf("%s, ", arr2[i]); } exit(EXIT_SUCCESS); }
๐ŸŒ
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.
๐ŸŒ
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 โ€บ 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.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ array-of-strings
Array of Strings in C Language (With Examples)
1 week 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.
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.
๐ŸŒ
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 ...
๐ŸŒ
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.