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 - 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…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
Coding your first program3m 40s
-
(Locked)
Challenge: Write your own code51s
-
(Locked)
Solution: Write your own code1m 50s
-
(Locked)
Getting into the C language2m 34s
-
(Locked)
Reviewing code structure3m 52s
-
(Locked)
Working the C development cycle3m 45s
-
(Locked)
Challenge: Find and fix the bugs43s
-
(Locked)
Solution: Find and fix the bugs1m 28s
-
(Locked)
Exploring the preprocessor3m 23s
-
(Locked)
Understanding header files and libraries3m 19s
-
(Locked)
Adding comments2m 49s
-
(Locked)
Chapter challenge: Building the foundation1m 11s
-
(Locked)
Chapter solution: Building the foundation1m 38s
-
-
-
Understanding C language data types3m 17s
-
(Locked)
Declaring variables2m 53s
-
(Locked)
Working with variables3m 4s
-
(Locked)
Exploring the printf() function3m 48s
-
(Locked)
Using constants2m 58s
-
Challenge: Making variables and constants53s
-
(Locked)
Solution: Making variables and constants1m 16s
-
(Locked)
Understanding variable scope3m 35s
-
(Locked)
Making new data types3m 25s
-
(Locked)
Specifying characters and strings3m 17s
-
(Locked)
Specifying integers and real numbers3m 55s
-
(Locked)
Typecasting a variable2m 20s
-
(Locked)
Chapter challenge: Adding variables and constants1m 10s
-
(Locked)
Chapter solution: Adding variables and constants2m 7s
-
-
-
Working with math operators3m 13s
-
(Locked)
Challenge: Do some math50s
-
(Locked)
Solution: Do some math1m 47s
-
(Locked)
Using assignment operators1m 49s
-
(Locked)
Obeying the order of precedence3m 14s
-
(Locked)
Challenge: Get the order correct55s
-
(Locked)
Solution: Get the order correct1m 37s
-
(Locked)
Working with relational operators3m 48s
-
(Locked)
Using logical operators3m 58s
-
(Locked)
Understanding bitwise operators3m 44s
-
(Locked)
Shifting bits3m 13s
-
(Locked)
Exploring unary operators3m 3s
-
Chapter challenge: More math1m 8s
-
(Locked)
Chapter solution: More math2m 45s
-
-
-
Making a decision3m 25s
-
(Locked)
Exploring the possibilities2m 53s
-
(Locked)
Using the ternary operator3m
-
Working with the switch-case structure4m
-
(Locked)
Challenge: Select an item28s
-
(Locked)
Solution: Select an item1m 45s
-
Creating a for loop3m 36s
-
(Locked)
Setting up a while loop2m 58s
-
(Locked)
Challenge: Repeat some text51s
-
(Locked)
Solution: Repeat some text1m 51s
-
(Locked)
Nesting loops1m 59s
-
(Locked)
Breaking out of a loop3m 16s
-
(Locked)
Avoiding the goto keyword1m 33s
-
(Locked)
Chapter challenge: Interpreting commands2m 26s
-
(Locked)
Chapter solution: Interpreting commands3m 55s
-
-
-
Understanding functions3m 11s
-
(Locked)
Creating a function4m 52s
-
(Locked)
Challenge: Writing a function39s
-
(Locked)
Solution: Writing a function1m 49s
-
(Locked)
Returning a value from a function2m 23s
-
(Locked)
Challenge: Returning a value53s
-
(Locked)
Solution: Returning a value2m
-
(Locked)
Passing arguments to a function2m 22s
-
(Locked)
Challenge: Passing values41s
-
(Locked)
Solution: Passing values1m 50s
-
(Locked)
Using the main() function's arguments2m 13s
-
(Locked)
Retaining values in a function2m 34s
-
(Locked)
Creating recursive functions3m 44s
-
(Locked)
Chapter challenge: Write the functions1m 14s
-
(Locked)
Chapter solution: Write the functions2m 15s
-
-
-
Understanding arrays2m 48s
-
(Locked)
Working with arrays2m 51s
-
(Locked)
Challenge: Creating an array55s
-
(Locked)
Solution: Creating an array1m 41s
-
(Locked)
Passing an array to a function2m 45s
-
(Locked)
Working with multi-dimensional arrays2m 42s
-
(Locked)
Building a structure3m 31s
-
(Locked)
Nesting structures3m 17s
-
(Locked)
Challenge: Constructing a structure1m 3s
-
(Locked)
Solution: Constructing a structure3m 5s
-
(Locked)
Putting structures into an array2m 37s
-
(Locked)
Working with structures and functions3m 47s
-
(Locked)
Chapter challenge: Manipulating a structure1m 22s
-
(Locked)
Chapter solution: Manipulating a structure2m 4s
-
-
-
Using single character I/O3m 32s
-
(Locked)
Testing and converting characters3m 15s
-
(Locked)
Challenge: Character I/O and conversions34s
-
(Locked)
Solution: Character I/O and conversions1m 37s
-
(Locked)
Understanding strings in C2m 46s
-
(Locked)
Fetching string input3m 45s
-
(Locked)
Sending string output3m 41s
-
(Locked)
Challenge: Using printf placeholders1m 9s
-
(Locked)
Solution: Using printf placeholders1m 59s
-
(Locked)
Exploring string functions2m 41s
-
(Locked)
Manipulating strings2m 57s
-
(Locked)
Chapter challenge: Reading commands1m 52s
-
(Locked)
Chapter solution: Reading commands2m 31s
-
-
-
Understanding pointers3m 23s
-
(Locked)
Using pointers to manipulate data2m 53s
-
(Locked)
Doing pointer math3m 10s
-
(Locked)
Comparing arrays and pointers5m 5s
-
(Locked)
Challenge: Output a string57s
-
(Locked)
Solution: Output a string2m 44s
-
(Locked)
Allocating storage3m 42s
-
(Locked)
Working with a pointer array4m
-
(Locked)
Using pointers in structures3m 8s
-
(Locked)
Challenge: Allocating structures1m 3s
-
(Locked)
Solution: Allocating structures3m 34s
-
(Locked)
Passing pointers to functions2m 23s
-
(Locked)
Returning pointers from a function2m 31s
-
Chapter challenge: Processing input1m 26s
-
(Locked)
Chapter solution: Processing input3m 14s
-
-
-
(Locked)
Reading from a file3m 31s
-
(Locked)
Writing to a file3m 40s
-
(Locked)
Challenge: Writing and reading files1m
-
(Locked)
Solution: Writing and reading files4m 4s
-
(Locked)
Working with raw data3m 4s
-
(Locked)
Using random file access3m 21s
-
(Locked)
Challenge: Access database records56s
-
(Locked)
Solution: Access database records2m 51s
-
(Locked)
Manipulating files2m 34s
-
(Locked)
Exploring the path1m 50s
-
(Locked)
Reading a directory3m 36s
-
(Locked)
Getting file information3m 26s
-
(Locked)
Chapter challenge: Managing files1m 46s
-
(Locked)
Chapter solution: Managing files2m 50s
-
(Locked)