title: Read multiple strings and float with multiple cases in C
body: <p>My main problem here is that I have two strings and a float to read. The strings' size is 10 bytes, but I should be able to read no matter what input it is and store it inside the strings.
  For example:
  if my input is <code>Hello world!</code> then the string should be <code>string = &quot;Hello wor&quot;</code></p>
  <p>if my input is <code>Hello</code> then the string should be <code>string = &quot;Hello&quot;</code></p>
  <p>Now you might think this is obvious, just use fgets right? But that presents buffer problems when reading a second string. The thing is, I did find a fix, but that involves using the fflush function, but it appears that it doesn't work in a few compilers.</p>
  <p>I searched for an alternative and found <code>while ( getchar() != '\n')</code> but it actually doesn't work like fflush.</p>
  <p>So what I'm asking here is there's a better alternative to read a string no matter the length of the input? This is what I came up with:</p>
  <pre><code>#include &lt;stdio.h&gt; 
  #include &lt;string.h&gt;
  
  int main(int argc, char** argv) {
      char nom[10] , prenom[10];
      double salaire;
      fgets( nom , sizeof( nom ) , stdin );
      nom[ strcspn( nom , &quot;\n&quot;) ] = 0;
      fflush(stdin);
      fgets( prenom , sizeof( prenom ) ,stdin );
      prenom[ strcspn( prenom , &quot;\n&quot;) ] = 0;
      fflush(stdin);
      scanf(&quot;%lf&quot;,&amp;salaire);
      printf(&quot;%s\n&quot;,nom);
      printf(&quot;%s\n&quot;,prenom);
      printf(&quot;%lf\n&quot;,salaire);
    return 0;
  }
  </code></pre>