Skip to content

Instantly share code, notes, and snippets.

@Kreyren
Created January 20, 2020 15:11
Show Gist options
  • Select an option

  • Save Kreyren/81bde657ba7e6aa986db8c19d244fa3d to your computer and use it in GitHub Desktop.

Select an option

Save Kreyren/81bde657ba7e6aa986db8c19d244fa3d to your computer and use it in GitHub Desktop.
Became master of C programming under 1,24sec using one short command!
( die(){ printf 'FATAL: %s\n' "$1" ;} ; mkdir -p "$HOME/C-Calculator/src" && printf '%s\n' "#include <stdio.h>" "#include <stddef.h>" '' "int main() {" " // Using float instead of double since it takes less space -> Experimenting if this is better then double" " float num1;" " float num2;" " char op; // Operator" " // Ask for user-input" " printf(\"%s\\n\",\"Enter first number: \");" " scanf(\"%f\", &num1);" " printf(\"%s\\n\", \"Enter an operator: \");" " scanf(\" %c\", &op);" " printf(\"%s\\n\",\"Enter Second number: \");" " scanf(\"%f\", &num2);" " // Action" " if(op == '+') {" " printf(\"Result: %f\\n\", num1 + num2);" " return 0;" " } else if(op == '-') {" " printf(\"Result: %f\\n\", num1 - num2);" " return 0;" " } else if(op == '*' || op == 'x') {" " printf(\"Result: %f\\n\", num1 * num2);" " return 0;" " } else if (op == '/' || op == ':') {" " printf(\"Result: %f\\n\", num1 / num2);" ' return 0;' ' } else {' " printf(\"Unknown operator '%c' has been parsed\\n\", op);" ' return 2; // Return 2 for syntax error' ' }' '}' > "$HOME/C-Calculator/src/main.c" && { cd "$HOME/C-Calculator/" || die "Your 'cd' is piece of shit" ;} && { gcc "$HOME/C-Calculator/src/main.c" || if ! command -v gcc >/dev/null; then die "Install GCC u pleb"; fi || die "GCC failed to compile your calculator, welcome to hell" ;} && chmod +x "$HOME/C-Calculator/a.out" ; "$HOME/C-Calculator/a.out" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment