In C, a string is actually stored as an array of characters, so the 'string pointer' is pointing to the first character. For instance,

char myString[] = "This is some text";

You can access any character as a simple char by using myString as an array, thus:

char myChar = myString[6];
printf("%c\n", myChar); // Prints s

Hope this helps! David

Answer from David Oakley on Stack Overflow
🌐
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. Let's take a look at an example: ... #include <stdio.h> #include <string.h> int main() { char *s = "Hello"; char arr[20]; // Convert the string ...
Discussions

How do I convert a string to an array of chars in C?
toupper returns a value. You have to assign that value to something to keep it. Your new array is both redundant, and is missing space for a null-terminator '\0' More on reddit.com
🌐 r/cs50
6
3
March 21, 2023
How to convert string to char array in C++? - Stack Overflow
I would like to convert string to char array but not char*. I know how to convert string to char* (by using malloc or the way I posted it in my code) - but that's not what I want. I simply want to More on stackoverflow.com
🌐 stackoverflow.com
Convert string to array of strings in C - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 10 years ago. So I have a string called c. I am reading it in from a file using this: ... I have another variable declared as char* array[41]. I need this to be an array of the individual ... More on stackoverflow.com
🌐 stackoverflow.com
June 12, 2017
c++ - converting a std::string to an array of c strings - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 13 years ago. I'm trying to find a way to convert a string to array of c strings. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 4
3

First of all, it already is a character array, NULL-terminated. You can simply choose to make another pointer to it, by saying char *c = argv[1];, or you can copy the entire string (null-terminator and all) into another array using the strcpy(char *destination, char *source)function http://www.cplusplus.com/reference/clibrary/cstring/strcpy/ like this:

char c[BUFFER]; //This has to be big enough to hold length + 1
strcpy(c, argv[1]);

Either approach is valid.

2 of 4
3

You can treat argv[1] as though it were an array of char (i.e., you can subscript it as argv[1][i]). You can pass it as an argument to any function that doesn't try to modify it (e.g., printf, strtol, strchr, etc.). You cannot write to it, though, so if you need to modify the contents for any reason (either directly or through a function like strtok or strcpy), you'll have to create a local copy and manipulate that.

If you are using C89 or earlier, use this method:

#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
  char *c = NULL;
  if (argc >= 2)
  {
    c = malloc(strlen(argv[1]) + 1);
    strcpy(c, argv[1]);
  }
  /**
   * Do stuff with c
   */
  free(c);
  return 0;
}

If you are using C99, you can use a VLA:

#include <string.h>

int main(int argc, char **argv)
{
  if (argc < 2)
    return 0;

  size_t len = strlen(argv[1]);
  char c[len+1];
  strcpy(c, argv[1]);
  /**
   * do stuff with c
   */
  return 0;
}

Just remember a few things:

  1. The type of argv is char **, not char *[N]; similarly, the type of argv[i] is char *, not char [M]. In most circumstances it doesn't matter; you can use a subscript operator on a pointer as though it were an array (array subscripting is defined in terms of pointer arithmetic), but remember that pointers and arrays are not the same thing and are not always interchangeable;

  2. The value of argv[argc] is always NULL;

  3. Except when it is the operand of the sizeof or unary & operators or is a string literal being used as an initializer in a declaration, an expression of array type is converted ("decays") from "N-element array of T" to "pointer to T", and the value of the expression is the location of the first element;

  4. C doesn't have a string data type as such; strings are represented as 0-terminated sequences of char. String literals such as "hello" are stored in such a way that they exist over the lifetime of the program, and you can access them via a pointer value; attempting to modify them results in undefined behavior (i.e., don't do that).

🌐
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 › convert-a-string-to-integer-array-in-c-cplusplus
Convert a String to Integer Array in C/C++
#include <stdio.h> #include <string.h> void convertStringToArray(char str[], int arr[], int *size) { int i = 0, j = 0, num = 0; int len = strlen(str); for (i = 0; i <= len; i++) { // If current character is digit if (str[i] >= '0' && str[i] <= '9') { num = num * 10 + (str[i] - '0'); } // If comma or end of string else if (str[i] == ',' || str[i] == '\0') { arr[j] = num; j++; num = 0; } // Skip spaces } *size = j; } int main() { char str[] = "2, 6, 3, 14"; int arr[100]; int size = 0; int i, sum = 0; convertStringToArray(str, arr, &size); printf("arr[] = "); for (i = 0; i < size; i++) { printf("
🌐
DcodeSnippet
dcodesnippet.com › home › programming › efficient ways to convert string to array in c programming
Efficient Ways To Convert String To Array In C Programming | DcodeSnippet
May 15, 2024 - When it comes to converting a string to an array in C, one common method is using the strtok() function. This function is part of the C standard library and is specifically designed for splitting a string into smaller tokens based on a delimiter.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › convert-a-string-to-integer-array-in-c-c
Convert a String to Integer Array in C/C++ - GeeksforGeeks
June 14, 2023 - // C++ program to convert a string to // integer array #include <bits/stdc++.h>; using namespace std; // Function to convert a string to // integer array void convertStrtoArr(string str) { // get length of string str int str_length = str.length(); ...
Find elsewhere
🌐
Silicon Cloud
silicloud.com › home › how to convert a string into an array in c language?
How to convert a string into an array in C language? - Blog - Silicon Cloud
March 22, 2024 - Therefore, you can directly assign a string to a character array to turn the string into an array. The following is an example code: #include int main() { char str[] = "Hello"; // 字符串赋值给字符数组 // 遍历字符数组并打印每个字符 for (int i = 0; i
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 357914 › converting-string-to-character-array-in-c
Converting String to Character Array in ... [SOLVED] | DaniWeb
May 4, 2011 - For full Unicode fidelity (not Modified UTF-8), get UTF-16 with GetStringChars and convert as needed. Refs: Oracle JNI docs for GetStringUTFChars and GetStringUTFRegion / lengths. There are no strings in C. There are character arrays. The str in your above example is an array and can be used like one ( str[4] for instance). If you'd like to convert that to a non-const array you will need to create storage and copy the …
🌐
Medium
medium.com › @vikas234mv › convert-a-string-to-integer-array-in-c-c-58f427979e96
Convert a String to Integer Array in C/C++ | by Vikas | Medium
July 8, 2026 - #include <iostream> #include <vector> using namespace std; int main() { string str = "100 200 300"; vector<int> arr; string temp = ""; for (char ch : str) { if (ch == ' ') { arr.push_back(stoi(temp)); temp = ""; } else { temp += ch; } } if (!temp.empty()) arr.push_back(stoi(temp)); cout << "Array: "; for (int x : arr) cout << x << " "; return 0; } ... In the C programming language, strtok() is commonly used to divide a string into smaller tokens. Each token representing a number is converted into an integer using the atoi() function.
🌐
Edureka Community
edureka.co › home › community › categories › c++ › how to convert string to char array in c
How to convert string to char array in C | Edureka Community
June 15, 2022 - I want to convert a string to a char array, not a char*. I know how to convert a string to a char* ... to char char tab2[1024]; // ? return 0; }
🌐
TutorialsPoint
tutorialspoint.com › convert-string-to-char-array-in-cplusplus
How to convert string to char array in C++?
May 28, 2025 - Begin Assign value to string s. Copying the contents of the string to char array using strcpy() . End · #include <iostream> #include <string> #include <cstring> using namespace std; int main() { string str = "Tutorialspoint"; char c[str.size() ...
🌐
Quora
quora.com › What-are-the-steps-to-convert-String-to-Char-Array-in-C
What are the steps to convert String to Char Array in C? - Quora
Answer (1 of 12): As the answers say, a string is a char array, mostly. This answer is a bit wrong in some contexts. I am thinking of string constants specifically. A string constant should probably not be treated as a char array in terms of modifying it. If I say char *p = “string constant”; ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
easy way to convert a string to a character array - Programming - Arduino Forum
January 20, 2018 - is there an easy way to convert a string into a character array sort of like... String S1 = "hello"; char array[] = S1: or do I have to use a for or while loop.
🌐
Codecademy
codecademy.com › docs › c# › strings › .tochararray()
C# (C Sharp) | Strings | .ToCharArray() | Codecademy
December 14, 2024 - The .ToCharArray() method can also take optional parameters to convert a specific substring into a character array: char[] substringArray = stringName.ToCharArray(startIndex, length);