CS 100 Cheat Sheet
CS 100 Cheat Sheet
Terminal/Cygwin Commands
Command Description
ls List the items in your current directory/folder
cd dir_name Change your directory to the specified dir_name
cd .. Change your directory to the parent directory
pwd Tells you the full path to your current directory
mkdir dir_name Create a new directory with the name dir_name
rmdir dir_name Delete the directory with the name dir_name
touch file_name Create an empty file with the name file_name
rm file_name Delete the file with the name file_name
cp file1 file2 Copy file1 to file2
mv file1 file2 Rename or move file1 to file2
cat file Display the contents of file
./program_name Run the specified program (.out for Mac/Linux .exe for Windows)
Control + C Stops a program that is currently running
Control + D End of file (EOF) character
Compiling in Terminal/Cygwin
Command Description
gcc code.c Compiles code.c and creates either a.out or a.exe. Run with ./
gcc code.c -o name.out Compiles code.c and creates name.out
gcc code.c -Wall Compiles code.c, displays code warnings, and creates a.out or a.exe
gcc code.c -g Compiles code.c and creates a debuggable a.out or a.exe
C Language Basics
The Hello World Program – Use this as a template for all programs.
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
Types
Type Description Example Usage Print/Scan %
int Holds integers numbers 0, 25, -10 int i; %d
float Holds real numbers (with decimals) 0.0, 13.37, -10.5 float f; %f
double Holds more precise real numbers 0.000000000005 double d; %lf
char Holds a single character 'A', 'z', '1', ' [' char c; %c
printf() writes to the command line. It does not need the & on the variables it reads values from.
Examples:
Code Snippet Output
int i = 1; Value: 1
printf("Value: %d", i);
scanf() reads from the command line. It needs the & on the variables it stores values in.
Examples:
Code Snippet Input/Output