Question: You are to write a C++ program that will call your gawk program and collect/display the results of the gawk output. The first call to
You are to write a C++ program that will call your gawk program and collect/display the results of the gawk output. The first call to gawk should pass in the version option. You should print out the results to screen and it should display version 3.1.8. The second call to gawk should call the program stored in gawk.code that operates on the number.txt file. This call will return the 2 integers representing the column sums. From within your C++ program, you are to collect the results of the call and print these integer values to the standard ouput. You are then to add the two numbers together and print out the sum of the two numbers to standard output.
You will need to use the popen/pclose functions to perform your shell call to gawk and to gather the results back into your C++ program. This is a C interface in Unix so make sure you realize you are not working with C++ objects. See man 3 popen for details (the 3 means section three of the manual).
For getting numbers out of C-style strings (the results of the gawk command), you might want to use the C++ stringstream type. You will need to google how to do this. For debugging purposes, you should also print the strings that are going to be used with popen/pclose. See below for example output.
Your C++ program output should look like this:
gawk at: /people/cs/s/sxp127930/UTDallas/Courses/Spring2015/Programs/Program3/bin/gawk
Shellcmd1: /people/cs/s/sxp127930/UTDallas/Courses/Spring2015/Programs/Program3/bin/gawk --version
Shellcmd2: /people/cs/s/sxp127930/UTDallas/Courses/Spring2015/Programs/Program3/bin/gawk -f gawk.code numbers.txt
The first call to gawk returned:
GNU Awk 3.1.8
Copyright (C) 1989, 1991-2010 Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
The second call to gawk returned: 125 497
The sum of Column 1 is: 125
The sum of Column 4 is: 497
The Sum of the two numbers is: 622
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
