Use a temporary string in strcat instead of strcat(out[0],*pa);.

Also, make sure that you allocate enough memory for out.

int main()
{   
   char a[10]="abcdefg123";
   char temp[2] = {0};
   char *pa=a;

   // This is not good for `strcat`.
   // char *out[2]={"",""};

   // Use this instead.
   char out[2][20]={"",""};

   int counter=0;
   while(*pa != '\0'){
      temp[0] = *pa;
      if (counter%2==0){
         strcat(out[0], temp);
      }
      else{
         strcat(out[1], temp);
      }

      counter++;
      pa++;    
   } 
   printf("%s,%s\n",out[0],out[1]);

   return 0;
}
Answer from R Sahu on Stack Overflow
🌐
Quora
quora.com › How-do-I-convert-a-char-to-string-in-C
How to convert a char to string in C - Quora
Answer (1 of 6): C is a procedure oriented language. Unlike C++ it does not have any string object support or java that has string as a primitive data type. In C string is simply an array of characters but the only condition is that it must be terminated by a null character,i.e '\0’. To convert...
Discussions

C string, char and pointers - Stack Overflow
I think people are downvoting because the question seem to be very broad and inaccurate.. it would be better if you post some real situation and how you use chars in that .. ... A short answer won't do your question justice. You're asking about two of the most significant, but often misunderstood, aspects of C. First of all, in C, by definition, a string is an array of characters... More on stackoverflow.com
🌐 stackoverflow.com
Does c have strings
You’re just having an argument over what the definition of “string” is. Your argument has nothing to do with C. It’s what people are talking about when they say “arguing over semantics”. These arguments, where you both agree about what the truth is (you agree how C works), but you disagree over the semantics of the words you use to describe C (you disagree about what a “string” is). The C standard is not going to decide this argument for you. Neither is the dictionary. More on reddit.com
🌐 r/cprogramming
55
10
November 3, 2024
Convert single character string to char - C++ Forum
I'm trying to convert a single character string into a char. I would rather not have to use an array to try to keep the code simpler. Is there a method for changing the string into an array or do I just need to use a char array regardless? More on cplusplus.com
🌐 cplusplus.com
November 17, 2016
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
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Convert a char to a String - Programming - Arduino Forum
March 7, 2013 - I want to turn the result of Serial.read(), which returns a char, into a String. I've looked elsewhere to no avail. I've tested String test= String (NameOfChar) as suggested. Thanks!
🌐
Scaler
scaler.com › home › topics › convert char to string in c++
Convert Char to String in C++ - Scaler Topics
October 16, 2023 - If we assign a single character to a string then the string will contain only a single character which will eventually change of data type of character. Let's see the syntax to convert char to string using the assignment operator: ... In the above syntax, we have simply assigned a character/character variable to the string and it will be stored in the string variable.
🌐
Codecademy
codecademy.com › docs › strings
C | Strings | Codecademy
April 21, 2025 - The following declaration and initialization create a string of “Howdy”: char message[6] = {'H', 'o', 'w', 'd', 'y', '\0'}; ... Even though “Howdy” has only 5 characters, message has 6 characters due to the null character at the end ...
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
C Examples C Real-Life Examples ... C Study Plan C Interview Q&A C Certificate ... Strings are used for storing text/characters. For example, "Hello World" is a string of characters. Unlike many other programming languages, C does not have a String type to easily create string ...
🌐
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 - Further, we declare an empty array of type char to store the result i.e. result of the conversion of string to char array. Finally, we use strcpy() method to copy the character sequence generated by the c_str() method to the empty char array. ... #include <bits/stdc++.h> using namespace std; ...
Find elsewhere
Top answer
1 of 2
16

A short answer won't do your question justice. You're asking about two of the most significant, but often misunderstood, aspects of C.

First of all, in C, by definition, a string is an array of characters, terminated with a nul character, '\0'.

So if you say

char string1[] = "Hello";

it's as if you had said

char string1[] = {'H', 'e', 'l', 'l', 'o', '\0'};

When you use a string constant like "Hello" in your program, the compiler automatically constructs the array for you, as a convenience.

Next we have the character pointer type, char *. You called this a "string to a char array", but it's really a pointer to a single char. People often refer to char * as being C's "string type", and in a way it is, but it can be a misleading thing to say, because not every char * is a string, and more importantly C has very few mechanisms for automatically managing strings for you. (What I mean is that, in C, you can't just sling strings around as if they were a basic data type, like you can in C++ or BASIC. You typically have to worry about where they're stored, how they're allocated.)

But let's go back to the definition of a string. If a string is an array of characters, then why would a pointer to characters be useful for manipulating strings at all? And the answer is, pointers are always useful for manipulating arrays in C; pointers are so good at manipulating arrays that sometimes it seems as if they are arrays. (But don't worry, they're not.)

I can't delve into a full treatise on the relationship between arrays and pointers in C here, but a couple of points must be made:

If you say something like

char *string2 = "world";

what actually happens (what the compiler does for you automatically) is as if you had written

static char __temporaryarray[] = "world";
char *string2 = __temporaryarray;

And, actually, since string2 is a pointer to a character (that is, what it points at is characters, not whole arrays of characters), it's really:

char *string2 = &__temporaryarray[0];

(That is, the pointer actually points to the array's first element.)

So since a string is always an array, when you mentioned the string "world" in a context where you weren't using it to initialize an array, C went ahead and created the array for you, and then made the pointer point to it. C does this whenever you have a string constant lying around in your program. So you can later say

string2 = "sailor";

and you can also say things like

if(strcmp(string1, "Goodbye") == 0) { ... }

Just don't do

char *string3;

strcpy(string3, "Rutabaga");        /* WRONG!! *//

That's very wrong, and won't work reliably at all, because nobody allocates any memory for string3 to point to, for strcpy to copy the string into.


So to answer your question, you will sometimes see strings created or manipulated as if they are arrays, because that's what they actually are. But you will often see them manipulated using pointers (char *), because this can be extremely convenient, as long as you know what you are doing.

2 of 2
2

Why do I see some books using the pointers method while others use the normal definitions ?

Neither of those is more "normal" than the other. A string in C is purely a contiguous (uninterrupted) series of char terminated with a 0 char. You can refer to that with a char[], or you can refer to it with a char *, or a const char *, etc. They're all just ways of referring to the block of memory with the series of chars in it. Each is appropriate in different contexts, depending on how the code in question receives the string and what it's doing with it.

🌐
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 - This function automatically handles the copying of characters, including the null terminator ('\0'), ensuring the string is properly converted into a char array. There are also one other methods in C to convert a string to a char array.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - We can change individual characters of a string using their index: str[0] = 'h'. Strings can also be updated using standard library functions like strcpy() to replace the entire string.
🌐
University of Texas
farside.ph.utexas.edu › teaching › 329 › lectures › node21.html
Character strings
The null character is automatically added to the end of any character string enclosed in double quotes. Note that, since all character strings in C must be terminated by the (invisible) null character, it takes a character array of size at least n+1 to store an n-letter string.
🌐
Cplusplus
cplusplus.com › forum › beginner › 202674
Convert single character string to char - C++ Forum
November 17, 2016 - I'm trying to convert a single character string into a char. I would rather not have to use an array to try to keep the code simpler. Is there a method for changing the string into an array or do I just need to use a char array regardless?
🌐
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?

🌐
Arduino Forum
forum.arduino.cc › projects › programming
String to char* conversion - Programming - Arduino Forum
November 7, 2018 - Hi all, I am trying to convert a string to char*. I use the Serial.println function to examine the values inside the pointer and the first character is unknown (as in inverted ?). The serial monitor shows temp: 1010, lookUpvar:?010. Anyone knows why? void loop(){ String temp = "1010"; char* lookup_var; Serial.print("temp:");Serial.println (temp); strcpy(lookup_var, temp.c_str()); Serial.print("lookUpvar:");Serial.println (lookup_var); }
🌐
Swarthmore College
cs.swarthmore.edu › ~newhall › unixhelp › C_strings.html
Strings in C
char str[3]; // need space for chars in str, plus for terminating '\0' char str[0] = 'h'; str[1] = 'i'; str[2] = '\0'; printf("%s\n", str); // prints hi to stdout · C provides a library for strings.