Programming lesson
CSCI 247 Lab 1: Intro to C – Mastering Linux Command Line and C Basics
A comprehensive tutorial for CSCI 247 Lab 1 covering Linux command line basics, compiling C programs, and understanding data types with timely AI and gaming analogies.
Welcome to CSCI 247: Computer Systems I – Lab 1
This tutorial is designed to help you get started with C programming in a Linux environment. By the end of this lesson, you will be comfortable navigating the Linux command line, using editors like nano, compiling C code with gcc, and understanding basic C data types. Whether you're a beginner or need a refresher, this guide uses real-world examples from AI development and gaming to make concepts stick.
Why Linux and C Matter in 2026
In 2026, C programming remains the backbone of operating systems, embedded devices, and high-performance applications. From the latest AI models running on Linux clusters to game engines like Unreal Engine, C and its close cousin C++ dominate performance-critical code. Mastering the Linux command line is essential for any serious programmer. This lab gives you hands-on practice with both.
Part 1: Logging into Your Linux Account
To start, you'll need to log into the CS Linux machines. Use SSH (Secure Shell) from your terminal or an app like PuTTY on Windows. Your instructor will provide the hostname and credentials. Once logged in, you'll see a prompt like:
username@linux-11:~$This is your command line, where you'll type all commands. The bash shell interprets your input. If you're new, think of it as a text-based interface to control the computer—similar to how you'd use a terminal in a sci-fi movie.
Part 2: Linux Bare Basics – Navigating the Filesystem
Let's create a project directory for this course. Use the mkdir command:
mkdir csci247To see what's in your current directory, use ls:
lsYou should see csci247 listed. Now enter that directory with cd:
cd csci247Inside, create a subdirectory for Lab 1:
mkdir lab1
cd lab1Now copy a sample file from a remote location (provided by your instructor) into your lab1 folder:
cp /home/jagodzf/public_html/teaching/csci247/labs/lab1/helloClass.txt .The dot . means “current directory.” Confirm the copy with ls -l (long listing):
ls -lYou can view the first 10 lines of the file using head:
head helloClass.txtAnd the last 10 lines with tail:
tail helloClass.txtTo edit the file, use nano:
nano helloClass.txtInside nano, you can read the file. The menu at the bottom shows shortcuts: ^X means Ctrl+X to exit. Practice opening, reading, and closing the file. For this lab, you'll find a “quiz answer” at the bottom – but don't just copy it; understand the context.
Part 3: Introduction to C – Your First Program
Now let's write a simple C program. Create a new file with nano:
nano hello.cType the following classic program:
#include <stdio.h>
int main() {
printf("Hello, CSCI 247!\n");
return 0;
}Save with Ctrl+O, then exit with Ctrl+X. Compile the program using gcc (GNU C Compiler):
gcc hello.c -o helloThe -o hello flag names the output executable. Run it:
./helloYou should see: Hello, CSCI 247! Congratulations, you've just compiled and run your first C program on Linux!
Part 4: Understanding C Data Types and Sizes
C provides several basic data types: int, float, double, char. Their sizes depend on the system. To see sizes, write a small program:
#include <stdio.h>
int main() {
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of char: %zu byte\n", sizeof(char));
return 0;
}Compile and run. On a typical 64-bit Linux system, you'll see int is 4 bytes, float is 4, double is 8, and char is 1. Understanding these sizes is crucial for memory management, especially in embedded systems and game development where every byte counts.
Part 5: String Manipulation in C
Strings in C are arrays of characters terminated by a null character (\0). Let's write a program that takes a name and prints a greeting. Create a file greet.c:
#include <stdio.h>
int main() {
char name[50];
printf("Enter your name: ");
scanf("%s", name);
printf("Hello, %s! Welcome to CSCI 247.\n", name);
return 0;
}Compile and run. This simple program demonstrates input/output and string handling. In real-world applications, like AI chatbots or network protocols, string manipulation is fundamental.
Part 6: Using an Editor and Compiler Efficiently
It's a good practice to open two terminal connections: one for editing and one for compiling/running. This way, you don't have to exit the editor each time. In one terminal, use nano to edit your code. In another, compile and test. This workflow mimics professional development environments where you have an IDE or editor plus a build terminal.
Part 7: Debugging with GDB (Optional but Recommended)
For debugging, you can use the GNU Debugger (GDB). Compile your program with the -g flag to include debugging symbols:
gcc -g hello.c -o helloThen run GDB:
gdb ./helloInside GDB, you can set breakpoints, step through code, and inspect variables. For example:
(gdb) break main
(gdb) run
(gdb) next
(gdb) print name
(gdb) quitDebugging is a critical skill, especially when working on complex systems like game engines or AI frameworks.
Part 8: Real-World Analogy – C in AI and Gaming
Think of C as the “assembly language” for high-level concepts. In 2026, many AI models are still implemented in C or C++ for performance. For example, the TensorFlow runtime uses C for low-level operations. Similarly, game engines like Unity's IL2CPP compile C# to C++ for speed. By learning C now, you're building a foundation for understanding how computers really work.
Part 9: Lab Tips and Common Pitfalls
- Remember the semicolon: Every statement in C ends with a semicolon. Missing one is the most common error.
- Case sensitivity:
mainis not the same asMain. C is case-sensitive. - Include headers: For
printfandscanf, you need#include <stdio.h>. - Use the man pages: Type
man printfto learn about functions. - Practice the command line: The more you use it, the faster you'll become.
Conclusion
This lab introduces you to the essential tools of a C programmer: the Linux command line, the nano editor, the gcc compiler, and basic C syntax. By completing these exercises, you gain hands-on experience that will serve you throughout your computer science career. In future labs, you'll dive deeper into pointers, memory allocation, and system calls. Remember, the command line is your friend—embrace it!