Lab 1 — File I/O and X11 Basics
CMPS 3600 • Fall 2025
CMPS 3600 • Fall 2025
This lab practices file I/O in C/C++ and introduces X11 graphics. We will write a small C++ program, refactor it to ANSI C, and then build and modify an X11 windowed C program. Steps duplicate only what is new beyond Lab 0.
If your ~/cs3600/1/
folder is not set up, run the instructor scripts. Otherwise, skip to Step 2.
$ cd
$ /home/fac/dfanucchi/public_html/build_dirs.sh
~/cs3600/1/
:
$ /home/fac/gordon/p/3600/lab-start.sh
lab1.cpp
that:
log
$ g++ lab1.cpp -Wall
$ ./a.out
$ cp lab1.cpp lab1.c
Log out and log back in with X11 forwarding and compression so GUI windows can display on your machine.
$ <CTRL-D> # disconnect from Odin
$ ssh -YC YOUR_USER@odin.cs.csub.edu
The options mean: -Y = trusted X11 forwarding, -C = compress data.
Note: If you are using a personal laptop or non-CSUB device, you must have X11 graphics configured locally. See the setup guide here: Laptop X11 Setup Instructions.
$ cd ~/cs3600/1
$ cp ~gordon/public_html/3600/examples/1/xwin89.c .
$ gcc xwin89.c -Wall -lX11
$ ./a.out
You should see a small window appear.
School color background.
Change the background to CSUB gold. Use XSetForeground
and XFillRectangle
.
In a C comment, cite where you found the X function info (e.g., a manpage or doc site).
You may use a CSUB color reference; see the official color codes here: CSUB Roadrunners Color Codes.
Mouse motion logging.
When the mouse moves inside the window, print a single m
to the terminal using write(2)
.
Flush on each event. Do not print a newline.
(Optional) Draw text.
Explore XDrawString
(man XDrawString
) to draw your name or instructions.
For example, pressing A could toggle the window background between blue and gold.
Hint: You will need to select and handle input events in the X11 event loop.
Add lab1.c
and xwin89.c
targets so make
builds both. Example:
CXX := g++
CC := gcc
CXXFLAGS := -std=c++17 -Wall -Wextra -O2
CFLAGS := -std=c17 -Wall -Wextra -O2
all: lab1 xwin89
lab1: lab1.cpp
$(CXX) $(CXXFLAGS) -o $@ $<
lab1-c: lab1.c
$(CC) $(CFLAGS) -o $@ $<
xwin89: xwin89.c
$(CC) $(CFLAGS) -o $@ $< -lX11
clean:
rm -f lab1 lab1-c xwin89
Test:
$ make clean
$ make
$ make # second time should say "Nothing to do"
Lab will be collected 9/2/2025 @ 11:59 PM
~/cs3600/1/lab1.cpp
~/cs3600/1/lab1.c
~/cs3600/1/xwin89.c
~/cs3600/1/Makefile