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
Step by step
Solved in 3 steps