need help with stopping the board from reading the initial value of the board

I need help with the code to stop it from reading the initial value of the board. For example if the ousb board initial value is 0,it should print out 1,2,3,4 .... and so on until it reaches the restriction. I have tried moving the cout line and the "vin=vin+operand1" so if possible can anyone help me thx.Also I am new to piping so if you think some parts are unnecessary feel free to edit it.


#include <iostream>
#include <cstdlib>
#include <math.h>
#include <stdio.h>
#include <windows.h>

using namespace std;

int main(int argc, char *argv[])
{//start of int main

if (argc == 1)
{

return 0;
}

if(atof(argv[1])- atoi(argv[1]) != 0 )
{
cout<<"X"<<endl;
}

else if(atof(argv[2])- atoi(argv[2]) != 0 )
{
cout<<"X"<<endl;
}

else{//start of else after error check2
int vin;
int operand1,operand2;
operand1 = atoi(argv[1]);
operand2 = atoi(argv[2]);

//Error check 1
if(argc >= 4)
{
cout<<"P"<<endl;
}

else if(argc == 2)
{
if(operand1 > 255 || operand1 < -255)
{cout<<"R1"<<endl;}

else{//start of else cal

vin = operand1;

char line[256];
FILE *fp = popen("ousb -r io portb","r");
fgets(line, sizeof(line), fp);
pclose(fp);

char a[256];
sprintf(a, "ousb -r io portb %i" , vin);
fp = popen(a, "r");
fgets(line, sizeof(line), fp);
pclose(fp);

cout<<line<<endl;
}//end of else cal

}

else if(argc == 3)
{//range check
if(operand1 > 255 || operand1 < -255)
{cout<<"R1"<<endl;}

else if(operand2 > pow(2,16) && operand2 < 1 && operand2 == 0)
{cout<<"R2"<<endl;}

else{//start of else cal

for(int i=0; i<=operand2; i++)

{//start of loop

vin = vin + operand1;

FILE *fp = popen("ousb -r io portb","r");//help here lol
char line[256];
fgets(line, sizeof(line), fp);
pclose(fp);

if(line[0] == 'F')
{//start of exit
cout<<"Z"<<endl;
return 0;
}//end of exit

if(GetAsyncKeyState(VK_ESCAPE))
{
cout<<"ESCAPE-PRESSED"<<endl;
Sleep(1000);
return 0;
}

cout<<line<<endl;

char a[256];//lolhelp here
sprintf(a, "ousb -r io portb %i" , vin);
fp = popen(a, "r");
fgets(line, sizeof(line), fp);
pclose(fp);

}//end of loop

}//end of else cal


}//range check

}//end of else after error check2

if(GetAsyncKeyState(VK_ESCAPE))
{
cout<<"ESCAPE-PRESSED"<<endl;
Sleep(1000);
}

return 0;
}//end of main
Last edited on
Topic archived. No new replies allowed.