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
🌐
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?

Discussions

How can we convert an input string in c++ into an array
I want to convert an input string in c++ into an array containing each alphabet of the string as ots independent and individual element. How can we measure or count the More on sololearn.com
🌐 sololearn.com
6
4
In C, how can I convert a string to a character array? - Stack Overflow
Except when it is the operand of ... 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; C doesn't have ... 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
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
🌐
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
🌐
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(); ...
🌐
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; }
🌐
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.
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 136675-converting-string-into-array.html
Converting a string into an array?
#include<stdio.h> #include<stdlib.h> #include<string.h> float a,b[4],c; int main(void) { printf("Enter string up to 5 digits\n"); scanf("%s", &b[4], &b[3],&b[2],&b[1],&b[0]); printf("\n1st: %d", b[4]); printf("\n2nd: %d", b[3]); printf("\n3rd: %d", b[2]); printf("\n4th: %d", b[1]); printf("\n5th: %d", b[0]); return 0; } ... A string is an array of chars with a zero at the end.
Find elsewhere
🌐
Facebook
facebook.com › groups › cs50 › posts › 1706949422785429
How to convert string to char array in C programming
Explore the things you love · Log into Facebook · English (US) · فارسی · العربية · Türkçe · Deutsch · Français (France) · Polski · More languages…
🌐
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”; ...
🌐
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 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
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).

🌐
DaniWeb
daniweb.com › programming › software-development › threads › 357914 › converting-string-to-character-array-in-c
Converting String to Character Array in C
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 …
🌐
UiPath Community
forum.uipath.com › help › studio
String to Array in C# - Studio - UiPath Community Forum
February 8, 2023 - Hi All, I am using C# in UiPath I have a string data ‘a’,‘b’,‘c’ and would need to convert into list or array and loop through it Can anyone suggest ?
🌐
TutorialsPoint
tutorialspoint.com › convert-string-to-char-array-in-cplusplus
How to convert string to char array in C++?
May 28, 2025 - This is a C++ program to convert string to char array in C++. This can be done in multiple different ways We can simply call strcpy() function to copy the string to char array.
🌐
Quora
quora.com › How-do-I-convert-a-string-array-to-an-object-in-C
How to convert a string array to an object in C - Quora
Answer (1 of 3): A string array already is an object in C. In C parlance, an object is a region of memory which is used by the program to store a particular piece of information. C does not use the object oriented paradigm, so the modern programming connotations don’t really apply.