title: Is it possible to use sscanf in C to create the alias command in a shell?
body: <p>I'm currently trying to create a shell in C that will mimic specific Unix commands. Right now I'm trying to use sscanf() to create the alias command, but I keep having issues trying to get it to work. Due to these issues, I'm beginning to wonder if it's even possible to use this function to create the alias command.</p>
  
  <pre><code>char *str=malloc(5000);
  /*
  ...
  */
  
  
   /*Function to alias commands*/
      int aliasing(char *str)
      {
              char *new_name=malloc(5000);
              char *alias_val=malloc(5000);
  
              sscanf(str,"alias %s=\"%s\"", new_name, alias_val);
      }
  </code></pre>
  
  <p>To avoid posting most of the main() code, I used "..." to cut it out. My understanding of sscanf() is that it takes the input from user in the shell, str (assuming they typed in alias (something)="(unix command)"), then assigns the first %s to new_name, and the second %s to alias_val. However, new_name is being assigned the entire string after alias and alias_val isn't getting anything.</p>
  
  <p>This has me questioning if it is even possible to use sscanf() this way, which brings me here. Any kind of feedback or ideas to fix the issue would be much appreciated. Also, if it's not possible to use sscanf() is there an alternative method to implementing the alias command?</p>