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 char
s each, after which the content of the static strings will be copied into them.
Related Posts:
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- Return char[]/string from a function
- How to clear all the elements of array in C?
- The difference between char * and char[] [duplicate]
- How does strtok() split the string into tokens in C?
- How to convert an int to string in C?
- What is a string of hexadecimal digits?
- How to convert an int to string in C?
- How do I determine the size of my array in C?
- How to convert a string to integer in C?
- char *array and char array[]
- “Expected expression before ‘ { ‘ token”
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- What is the difference between char s[] and char *s?
- How to print the array?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- How do I properly compare strings in C?
- How do you make an array of structs in C?
- How to convert an int to string in C?
- Returning string from C function
- How to check if a string is a number?
- Why am I getting “array initializer must be an initializer list or string literal”?
- Using Dynamic Memory allocation for arrays
- How do I lowercase a string in C?
- How do I create an array of strings in C?
- Finding the length of a Character Array in C
- How to print a char array in C through printf?
- How do I concatenate const/literal strings in C?
- Reversing a string in C
- How to remove the character at a given index from a string in C?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- Split string with delimiters in C
- How to create an array of strings in C?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Convert char array to string use C
- Iterate through a C array
- Allocating string with malloc
- What is the difference between char array and char pointer in C?
- Removing trailing newline character from fgets() input
- Does C have a string type?
- Array type char[] is not assignable
- How to concatenate string and int in C?
- How do I check if a string contains a certain character?
- warning: implicit declaration of function
- Why should we typedef a struct so often in C?
- What is the difference between ++i and i++?
- Array to String PHP?
- Undefined reference to pthread_create in Linux
- Stack smashing detected
- Why am I getting “void value not ignored as it ought to be”?
- Pointer Arithmetic
- Openssl : error “self signed certificate in certificate chain”
- Expression must be a modifiable L-value
- How do I use valgrind to find memory leaks?
- Error “initializer element is not constant” when trying to initialize variable with const
- munmap_chunk(): invalid pointer
- What is the LD_PRELOAD trick?
- What is the argument for printf that formats a long?
- Using %s in C correctly – very basic level
- How to create my own header file in c++?
- Is there a function to copy an array in C/C++?
- Why do I get an assertion failure?
- Char Comparison in C
- C – The %x format specifier
- what is the unsigned datatype?
- Reading a string with scanf
- getopt_long() — proper way to use it?
- C read file line by line
- C read file line by line
- Copying a part of a string (substring) in C
- expression must have integral type
- Incompatible implicit declaration of built-in function ‘malloc’
- Why is %c used in C?
- Need more information about Aborted (core dumped)
- splitting a string into an array in C++ without using vector
- When a number is written as 0x00… what does the x mean
- waitpid, wnohang, wuntraced. How do I use these
- what is Ljava.lang.String;@
- Writing binary number system in C code
- Returning an array using C
- Scanning Multiple inputs from one line using scanf
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- How to empty a char array?
- Checking if a string array contains a value, and if so, getting its position
- How do you allow spaces to be entered using scanf?
- Which of sprintf/snprintf is more secure?
- Allocating char array using malloc
- Implementation of strtok() function
- switch case: error: case label does not reduce to an integer constant
- warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
- warning: return makes pointer from integer without a cast but returns integer as desired
- Dynamic vs static array in c
- How to clear input buffer in C?
- What primitive data type is time_t? [duplicate]
- Convert long long to string in C?
- Compiler warning – suggest parentheses around assignment used as truth value
- lvalue required as increment operand