moister-detection-4/README.md
2026-10-05 08:20:38 -06:00

963 B

Moisture Detection 4

The moisture log again, walked with a pointer instead of an index.

What is what

File
stride.c Part A run it, read it but do not edit it
walk.c Parts B and C your code goes here, at each YOUR TASK

What to do

  1. Part A. Before you run stride, write down how many bytes apart p and p + 1 are for a char, an int and a double, and what *(pi + 1) and (pi + 3) - pi print. Then run it and compare.
  2. Part B. In walk.c, write sum_ptr() and find(). You are done when every check line says PASS.
  3. Part C. In sum_ptr(), change < to <= so the pointer also reads at levels + count. Predict, then run it with the plain build and with AddressSanitizer. Put < back.

Build and run

gcc -std=c17 -Wall -Wextra -o stride stride.c
./stride
gcc -std=c17 -Wall -Wextra -o walk walk.c
./walk

For Part C, add -fsanitize=address -g to the walk line.