You can use 2D array to store multiple strings. For 10 strings each of length 100

char variable[10][100];

printf("Enter Strings\n");
for (int i = 0; i < 10 ;i++)  
    scanf("%100s", variable[i]); 

Better to use fgets to read string.

fgets(variable[i], sizeof(variable[i]), stdin);  

You can also use dynamic memory allocation by using an array of pointers to char.

Answer from haccks on Stack Overflow
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 175792-multiple-strings-storing-array.html
multiple strings storing in array
Program for storing multiple letters Code: #include int main (void) { unsigned int i; char array[6]={'s','e','a','r','c','h'}; for(i=0;
🌐
GeeksforGeeks
geeksforgeeks.org › c language › array-of-strings-in-c
Array of Strings in C - GeeksforGeeks
July 23, 2025 - In C, an array of strings is a 2D array where each row contains a sequence of characters terminated by a '\0' NULL character (strings). It is used to store multiple strings in a single array.
🌐
YouTube
youtube.com › engineer thileban explains
How To Store Multiple String Values In An Array Using C Programming - YouTube
How To Store Multiple String Values In An Array Using C Facebook :- https://www.facebook.com/EngineerThilebanExplains/ Google + :- https://plus.google.com/u/...
Published   June 5, 2018
Views   8K
Top answer
1 of 2
4

How store multiple string or create an array of strings in C, by using 1D array?

The short answer is: You can't

A string in C is by itself a char array (with a zero termination) so there is no way to have multiple strings in a 1D array.

You can make it a 2D array like:

int main()
{
  // Make a 2D array to store
  // 4 strings with 9 as max strlen
  char str[4][10] = {"Linux", "Ubuntu", "Arch", "Void"};

  for (int i=0; i<4; ++i) printf("%s\n", str[i]);
  return 0;
}

Another approach is to use a 1D array of char pointers to string literals - like:

int main()
{
  // Make a 1D array to store
  // 4 char pointers
  char *str[4] = {"Linux", "Ubuntu", "Arch", "Void"};

  for (int i=0; i<4; ++i) printf("%s\n", str[i]);
  return 0;
}

but notice that the strings are not saved in the array. The compiler place the strings somewhere in memory and the array just holds pointers to those strings.

Also notice that in the second example you are not allowed to modify the strings later in the program. In the first example you are allowed to change the strings after the initialization, e.g. doing strcpy(str[0], "Centos");

BTW: This may be of interrest Are string literals const?

2 of 2
0

It is possible to store multiple strings in a 1D array - the issue is accessing anything beyond the initial string. For example:

char strs[] = “foo\0bar\0bletch\0blurga”;

The 1D array strs contains 4 strings, but if we pass strs to any library function, only ”foo” will be used.. We would need to maintain a separate array of pointers into strs to access anything beyond the first string:

char *ptrs[] = {strs, &strs[4], &strs[8], &strs[15]};

If you need your strings to be contiguous in memory then this is a valid aproach, but it is cumbersome, and will be a massive pain in the ass if you need to update any of them. Better to use a 2D array.

🌐
Reddit
reddit.com › r/learnprogramming › [c] can i store strings into an array ?
r/learnprogramming on Reddit: [C] Can I store strings into an array ?
October 5, 2021 -

I know that strings are char arrays already and I was wondering if there's a way to store not strings in an array. It would be like storing arrays into an array and that sounds a bit weird.

As far as I know an array is a pointer so I'd tend to say no, but after all pointers are just storing numbers like any variable.

To maybe be clearer, what I'd want to do is have an array that's like that :

array[0] = BLUE

array[1] = RED

array [2] = YELLOW

etc

🌐
CopyProgramming
copyprogramming.com › howto › storing-multiple-strings-in-an-array-in-c
Arrays: Storing numerous strings in a C array
April 26, 2023 - Since a string in C is essentially a char array with a zero terminator, it is not possible to store multiple strings in a 1D array.
🌐
Notes
notes.iamdev.in › home › how to store array of strings in c programming
How to Store Array of Strings in C Programming » Notes
July 12, 2024 - In C programming, arrays are fundamental data structures used to store collections of elements of the same type. When it comes to handling text or multiple strings, arrays of characters (strings) become very useful. This tutorial will guide you through the process of storing and working with ...
Find elsewhere
🌐
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 - In the C programming language, you can declare an array of strings by creating an array of character pointers. This allows you to store multiple strings in a single variable.
🌐
Reddit
reddit.com › r/c_programming › can i store multiple strings in one variable without declaring it's size?
r/C_Programming on Reddit: Can I store multiple strings in one variable without declaring it's size?
February 14, 2021 -

So I'm new to C and programming and I'm trying to make a simple program to store a series of objects sorted by brand and model and keep that information inside the variable. I was wondering if there's such a way to store the brands names inside this variable called "brand" and later call a brand of my choice from that variable to be shown. Well, I'm pretty sure there's such thing, I've been looking for different data structures, maybe Array is not the suitable one.

Anyway, that's it, I don't want any kind of done stuff, I'm trying to make this project so I can learn more about C, learn to read documentation, learn the "why's" for what I'll be doing in the coding, learn how to look for solving my problem. Thank you already!

🌐
GitHub
github.com › TONEPIC › c_language_exercises › blob › master › Store multiple strings in an array
c_language_exercises/Store multiple strings in an array at master · TONEPIC/c_language_exercises
Dartmouth_IMTx - DART.IMT exercises from online course by Dartmouth_IMTx on edx - c_language_exercises/Store multiple strings in an array at master · TONEPIC/c_language_exercises
Author   TONEPIC
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-store-words-in-an-array-in-c
How to store words in an array in C? - GeeksforGeeks
October 18, 2019 - Lets say we need to fetch the ith word: array[i] Below is the implementation of the above approach: ... // C program to store words in an array #include <stdio.h> int main() { int i; // Direct initialization of 2-D char array char array[][20] = { "Geek1", "Geek2", "Geek3" }; // print the words for (i = 0; i < 3; i++) printf("%s\n", array[i]); return 0; }
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.

🌐
Quora
quora.com › How-can-we-store-values-into-an-array-of-characters-in-the-C-programming-language
How can we store values into an array of characters in the C programming language? - Quora
Answer: There are many ways to do so. Of course, you need space to store it. At least enough space for the larger possible string + 0 (end of string). Remember strings in C ends where the 0 is found, but not strings variables…. The first thing you need is to understand the difference between an...