From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Chapter solution: Sorting a grid

Chapter solution: Sorting a grid - C Tutorial

From the course: Complete Guide to C Programming Foundations

Chapter solution: Sorting a grid

(upbeat music) - [Instructor] Hopefully most of this challenge is easy for you, save for probably the final part. Here are the constants and variables I use in my solution. I set the grids, rows, and columns as constants, then use these constants to determine the grid's overall size. Variables are the grid buffer, and X and y for the nested loops. The randomizer is seated. Next comes allocation. It's based on the size of an integer times the grid size. A test is conducted to confirm proper allocation. The for loop populates the grid with random values based on the grid size. Pointer notation is used. The random value fetched from the rand function is clipped to values from zero through 99. Next, the grid is quick sorted, buffer address, size of the grid, size of an integer, and the compare function. Next comes the tricky part, outputting the grid. Here you see I've constructed the nested for loops. They plow through the rows and the columns, and remember that internally the grid is…

Contents