title: How to scanf full sentence in C
body: <p>How to <code>scanf()</code> full sentence  in C without using <code>fgets()</code> or <code>gets()</code></p>
  
  <p>I want to scan a command line from the user and based on the first word recognize the command. 
  For example:
      mkdir </p>
  
  <p>so I need to recognize that the user wants to create a new dir with the name "dir_name".</p>
  
  <p>My code:</p>
  
  <pre><code>int main(){
    char *ch=malloc(sizeof("50");
    while (strcmp(ch,"exit")!=0){
       scanf("%[^\n]",ch);
    } 
  </code></pre>
  
  <p>when i ran this code after i input the first sentence and press enter it went to infinity loop i don't know why?</p>