How to compile and run C in sublime text 3?

Have you tried just writing out the whole command in a single string?

{
"cmd" : ["gcc $file_name -o ${file_base_name} && ./${file_base_name}"],
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path"
}

I believe (semi-speculation here), that ST3 takes the first argument as the "program" and passes the other strings in as "arguments". https://docs.python.org/2/library/subprocess.html#subprocess.Popen


For a sublime build system implementing the Run menu command :

  • Go to Tools->Build System->New Build System...

Or

  • Create a file ~/.config/sublime-text-3/Packages/User/GCC.sublime-build

And insert this:

{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"variants":
  [
    {
      "name": "Run",
      "shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
    }
  ]
}

*This example uses the GCC compiler. Feel free to replace gcc with the compiler of your choice.