[code]#include <iostream> #include <cstdlib> #include <time.h> #include <sys/time.h> #include <errno.h> #include <math.h> #include <stdio.h> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { int num1,num2; char* end; if(argc==1) { cout<<"S3333435B,s3333435@student.rmit.edu.au,Matthew_Merigan" << endl ; system("pause"); return(0); } if(argc>3) { cout<<"P"<<endl; system("pause"); return(0); } FILE *fpipe; float param1=atof(argv[1]), param2=atof(argv[2]); if(argc==2||argc==3) { string comma1(argv[1]); string::size_type i = comma1.find(',', 0); while (i != string::npos) { comma1.erase(i,1); i = comma1.find(',', i); } double num1=strtod(comma1.c_str(),&end); if(*end!='\0') { cout<<"X"<<endl; system("pause"); return (0); } double param1=(int)num1; if(param1!=num1) { cout<<"X"<<endl; system("pause"); return (0); } string comma2(argv[2]); string::size_type j = comma2.find(',', 0); while (j != string::npos) { comma2.erase(j,1); j = comma2.find(',', j); } double num2=strtod(comma2.c_str(),&end); if(*end!='\0') { cout<<"X"<<endl; system("pause"); return (0); } double param2=(int)num2; if(param2!=num2) { cout<<"X"<<endl; system("pause"); return (0); } if(param1 > 255|| param1 < -255) { cout<<"R1"<<endl; system("pause"); return 0; } if (param2 > 65535 || param2 < 1) { cout << "R2" << endl; system("pause"); return 0; } char *command="ousb io PINC"; // Read the switch state. char line[256]; if ( !(fpipe = (FILE*)popen(command,"r")) ) { // error if fpipe returns NULL perror("Problems with pipe"); exit(1); } while ( fgets( line, sizeof (line), fpipe)) { printf("%s", line); } } system("pause"); pclose(fpipe); } [/code] |