title: getting the first n elements of a specified char array arduino
body: <p>My aim is reading some string from serial for example 234124!3455addg#5867 if the program sees ! it should start to add it to a char array and if it sees # it should return the first 4 elements of that char array for my example the return should be 3455. How can I solve it? I made this using String class but I need to implement it to char array.
  I am quite new on arduino so please be clear thank you. 
  Here is my code: </p>
  
  <pre><code>const char *s = "123123123!0037selam#aaaaSDSDa";
  const char *CHAR1 = "!";
  const char *CHAR2 = "#";
  
  char *target = NULL;
  char *start, *end;
  
  void setup() {
      Serial.begin(9600);
  }
  
  void loop() {
      if ( start = strstr( s, CHAR1 ) )
      {
          start += strlen( CHAR1 );
          if ( end = strstr( start, CHAR2 ) )
          {
              target = ( char * )malloc( end - start + 1 );
              memcpy( target, start, end - start );
              target[end - start] = '\0';
          }
      }
  
      if ( target )
      {
          for(int i=0; i&lt;4;i++)
              Serial.print( target[i]);
      }
  
      free( target );
      return 0;
  }
  </code></pre>