title: Flex / Lex Encoding Strings with Escaped Characters
body: <p>I'll refer to this question for some of the background:</p>
  
  <p><a href="https://stackoverflow.com/questions/2039795/regular-expression-for-a-string-literal-in-flex-lex">Regular expression for a string literal in flex/lex</a></p>
  
  <p>The problem I am having is handling the input with escaped characters in my lexer and I think it may be an issue to do with the encoding of the string, but I'm not sure.</p>
  
  <p>Here's is how I am handling string literals in my lexer:</p>
  
  <pre><code>\"(\\.|[^\\"])*\"
  {                   
      char* text1 = strndup(yytext + 1, strlen(yytext) - 2);
      char* text2 = "text\n";
  
      printf("value = &lt;%s&gt; &lt;%x&gt;\n", text1, text1);
      printf("value = &lt;%s&gt; &lt;%x&gt;\n", text2, text2);
  }
  </code></pre>
  
  <p>This outputs the following:</p>
  
  <pre><code>value = &lt;text\n"&gt; &lt;15a1bb0&gt;
  value = &lt;text
  &gt; &lt;7ac871&gt;
  </code></pre>
  
  <p>It appears to be treating the newline character separately as a backslash followed by an n. </p>
  
  <p>What's going on here, how do I process the text to be identical to the C input?</p>