Commands are passed to the command line of a Linux terminal in the format "\$COMMAND,PARAMETER1,PARAMETER2,...,PARAMETER5\r" i.e., the command begins with the identifying '$' symbol, followed by a command string, then a list of parameters separated by commas. A command can have up to 5 parameters, or no parameters. Parameters can be up to 5 characters in length. Commands end with a carriage return '\r'. Write a function void parse(char *input) that takes in Commands and parses them into a command string and an array of parameters. For the following Commands, print the command string and parameters of each: 1. $GETNUM,1\r 2. $GETSUM,2,3\r 3. $LISTNUMS,10,300,-40\r 4. $DONOTHING\r Expected outputs: 1. Command string = GETNUM Parameter[0]=1 2. Command string = GETSUM Parameter[0]=2 Parameter[1]=3 3. Command string = LISTNUMS Parameter[0]=10 Parameter[1]=300 Parameter[2]=-40 4. Command string = DONOTHING This command has no parameters
Commands are passed to the command line of a Linux terminal in the format "\$COMMAND,PARAMETER1,PARAMETER2,...,PARAMETER5\r"
i.e., the command begins with the identifying '$' symbol, followed by a command string, then a list of parameters separated by commas. A command can have up to 5 parameters, or no parameters. Parameters can be up to 5 characters in length. Commands end with a carriage return '\r'.
Write a function void parse(char *input) that takes in Commands and parses them into a command string and an array of parameters.
For the following Commands, print the command string and parameters of each:
1. $GETNUM,1\r
2. $GETSUM,2,3\r
3. $LISTNUMS,10,300,-40\r
4. $DONOTHING\r
Expected outputs:
1.
Command string = GETNUM
Parameter[0]=1
2.
Command string = GETSUM
Parameter[0]=2
Parameter[1]=3
3.
Command string = LISTNUMS
Parameter[0]=10
Parameter[1]=300
Parameter[2]=-40
4.
Command string = DONOTHING
This command has no parameters
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)