Write a C program which behaves as follows: If there are no command-line arguments at all when the program is run, the program should print out instructions on its use (a "usage message"). There should be one common usage message (consider a method/function for printing the usage message) for any type of usage error. The program will accept an A or D as the second command line argument (after the program name). This letter will tell you whether the bubble sort should sort in ascending or descending fashion. Anything other than A or D in that position should display the usage message and terminate the program. The program will be able to accept up to 32 numbers (integers) on the command line. If there are more than 32 numbers on the command line, or no numbers at all, the program should print out the usage message and exit with a non-zero value from main. This means 32 values not including the program name (argv[0]) and sort type. You may assume that the command line arguments (except for the sort type) are all integers. Sort the numbers using the bubble sort algorithm. Do not use a global array to hold the integers; use a locally-defined array in main and pass the array to the sorting function along with the type of sort (ascending or descending). Print out the sorted numbers, one per line. Your bubble sort function must be in its own separate file. The main() function should be in a file called main.c, along with supporting functions (like for printing a usage message). This program must be written in C (not C++). Note that if you're compiling on an OS, use the gcc command, not g++. Note also that since your program is in C, your source files should have a .c extension, not .cpp or .cxx.
Write a C program which behaves as follows: If there are no command-line arguments at all when the program is run, the program should print out instructions on its use (a "usage message"). There should be one common usage message (consider a method/function for printing the usage message) for any type of usage error. The program will accept an A or D as the second command line argument (after the program name). This letter will tell you whether the bubble sort should sort in ascending or descending fashion. Anything other than A or D in that position should display the usage message and terminate the program. The program will be able to accept up to 32 numbers (integers) on the command line. If there are more than 32 numbers on the command line, or no numbers at all, the program should print out the usage message and exit with a non-zero value from main. This means 32 values not including the program name (argv[0]) and sort type. You may assume that the command line arguments (except for the sort type) are all integers. Sort the numbers using the bubble sort algorithm. Do not use a global array to hold the integers; use a locally-defined array in main and pass the array to the sorting function along with the type of sort (ascending or descending). Print out the sorted numbers, one per line. Your bubble sort function must be in its own separate file. The main() function should be in a file called main.c, along with supporting functions (like for printing a usage message). This program must be written in C (not C++). Note that if you're compiling on an OS, use the gcc command, not g++. Note also that since your program is in C, your source files should have a .c extension, not .cpp or .cxx.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Write a C
- If there are no command-line arguments at all when the program is run, the program should print out instructions on its use (a "usage message"). There should be one common usage message (consider a method/function for printing the usage message) for any type of usage error.
- The program will accept an A or D as the second command line argument (after the program name). This letter will tell you whether the bubble sort should sort in ascending or descending fashion. Anything other than A or D in that position should display the usage message and terminate the program.
- The program will be able to accept up to 32 numbers (integers) on the command line.
- If there are more than 32 numbers on the command line, or no numbers at all, the program should print out the usage message and exit with a non-zero value from main. This means 32 values not including the program name (argv[0]) and sort type.
- You may assume that the command line arguments (except for the sort type) are all integers.
- Sort the numbers using the bubble sort
algorithm . Do not use a global array to hold the integers; use a locally-defined array in main and pass the array to the sorting function along with the type of sort (ascending or descending). - Print out the sorted numbers, one per line.
- Your bubble sort function must be in its own separate file. The main() function should be in a file called main.c, along with supporting functions (like for printing a usage message).
- This program must be written in C (not C++). Note that if you're compiling on an OS, use the gcc command, not g++. Note also that since your program is in C, your source files should have a .c extension, not .cpp or .cxx.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education