M. 0om question 6.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 

M. 0om question 6.

 

 

Write a C program that allocates memory using the malloc function for an array of size specified
by the user at runtime. Assign pseudo-random double values to the array elements, then sort
the array using the qsort function. Using the examples from the lecture, define a function that
compares numbers of type double. Pass the function address to the qsort function. Use the free
function to free up memory.
Problem 2:
Modify the source code of the program from Problem 1 to sort the string (character array).
When allocating memory to an array, be sure to add '\0' at the end of the array.
• Assign random letters from 'a' to 'z' to the array elements.
• Print the array of characters using the printf("%s\n", arr)…....; command.
• When using the qsort function, remember that '\0' must remain at the end of the array.
• Using the examples from the lecture, define a function that compares characters.
• Use the free function to free up memory.
Transcribed Image Text:Write a C program that allocates memory using the malloc function for an array of size specified by the user at runtime. Assign pseudo-random double values to the array elements, then sort the array using the qsort function. Using the examples from the lecture, define a function that compares numbers of type double. Pass the function address to the qsort function. Use the free function to free up memory. Problem 2: Modify the source code of the program from Problem 1 to sort the string (character array). When allocating memory to an array, be sure to add '\0' at the end of the array. • Assign random letters from 'a' to 'z' to the array elements. • Print the array of characters using the printf("%s\n", arr)…....; command. • When using the qsort function, remember that '\0' must remain at the end of the array. • Using the examples from the lecture, define a function that compares characters. • Use the free function to free up memory.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY