title: Unable to concatenate strings together and read one character at a time in C using a array from the command line
body: <p>I have been trying to simply concatenate several strings into one long string separated by spaces and then read each character of this new string one by one while printing it to the screen.  I have found similar topics on here which show how to use the command line arguments using the void main() so I hope I have started doing this correctly.  I am unsure if I am not understanding how ptr's work correctly or if I need a null character somewhere or if im not properly declaring the space for the variables to hole the new results.  Here is the snippet of code I have so far: </p>
  
  <pre><code>[jeff@srv1 screensend]# cat tty_send.c
  #include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;string.h&gt;
  
  
  int main(int argc, char *argv[])
  {
     int x;
     char text[256];
     int length;
     char str[20];
  
     if ( argc &lt; 2 )
     {
        printf( "usage: %s &lt;tty device file&gt; &lt;text to send&gt;\n", argv[0] );
     }
     else
     {
        text[0] = '\0';       //give strcat a starting point to concatenate to
        for ( x = 1; x &lt; argc; x++ ) {   //concatenate all the arguments into the variable 'text'
           strcat( text, argv[x] );
           if ( (x != (argc-1)) )    //re-add a space unless it's the last argument
           {
              strcat( text, " ");
           }
        }
     }
     printf("Sending '%s' to terminal \n", text);
     //char sizetest;
     //sizetest = sizeof(*argv);
     //printf("size: %s\n", sizetest);
  
     length = strlen(text);
     printf("length: %d\n", length);
     //printf("3rd character: %s\n", text[3]);
     //for ( x = 0; x &lt; length-1; x++ ){
        char myChar = text[1];
        //printf(myChar);
        printf("out: %s\n", myChar);         //&lt;------THIS GENERATES A SEGFAULT
     //}
  }
  [jeff@srv1 screensend]#
  </code></pre>
  
  <p>Here is my output so far:</p>
  
  <pre><code>[jeff@srv1 screensend]# ./tty_send test testing
  Sending 'test testing' to terminal
  length: 12
  Segmentation fault
  [jeff@srv1 screensend]#
  </code></pre>
  
  <p>I saw some other topics on here about concatenation however I think the issue here is when I'm trying to get the first character (second in this example) of the result of my concatenation I am trying to get the ptr value and print that out (which if this was the case, I feel like this should work as well and just appear like a memory address).  Any help would be much appreciated, i've been googleing and providing some daily side attention to this for over a week with no progress.</p>
  
  <p>Thank you,</p>
  
  <p>Jeff</p>