michiel-reenaers
November 14th, 2013, 08:41 PM
I'm beginning with c++ (only 2 days)
Does anyone know how you can make a script (that has a infinit loop) that checks the last line of a file continuously, Less resource unfriendly?
Right now I just have a while loop that is continuously true, that then reads the last line, and does some calculations.
But as you can guess that isn't so great for my cpu.
this is the main of my code:
int main() {
int q = 0;
do {
// RESET //
memcpy ( SAVEDSENTENCE, COMPLETESENTENCE, strlen(COMPLETESENTENCE)+1 );
memset(COMPLETESENTENCE, '\0', sizeof(COMPLETESENTENCE));
memset(SENTENCE, '\0', sizeof(SENTENCE));
memset(FUNCTIONNUMBER, '\0', sizeof(FUNCTIONNUMBER));
memset(THIRDVARIABLE, '\0', sizeof(THIRDVARIABLE));
//
// SETVARIABLES //
GetSentence();
//Check if this sentence matches previous sentence
if (memcmp(SAVEDSENTENCE, COMPLETESENTENCE, sizeof(SAVEDSENTENCE))== 0)
{
FUNCTIONNUMBER[0]='9';
}
switch (atoi(FUNCTIONNUMBER))
{
case 0: Result();
break;
case 1: LoadingDots();
break;
case 2: UserInputResult();
break;
case 3: ChangeColor();
break;
}
double timeInterval;
for ( timeInterval = 0; timeInterval <= 900000000; timeInterval++);
}
while (q == 0);
}
I compile with g++ (should that make a difference).
Feel free to give some other tips on making the code less resource demanding.
Does anyone know how you can make a script (that has a infinit loop) that checks the last line of a file continuously, Less resource unfriendly?
Right now I just have a while loop that is continuously true, that then reads the last line, and does some calculations.
But as you can guess that isn't so great for my cpu.
this is the main of my code:
int main() {
int q = 0;
do {
// RESET //
memcpy ( SAVEDSENTENCE, COMPLETESENTENCE, strlen(COMPLETESENTENCE)+1 );
memset(COMPLETESENTENCE, '\0', sizeof(COMPLETESENTENCE));
memset(SENTENCE, '\0', sizeof(SENTENCE));
memset(FUNCTIONNUMBER, '\0', sizeof(FUNCTIONNUMBER));
memset(THIRDVARIABLE, '\0', sizeof(THIRDVARIABLE));
//
// SETVARIABLES //
GetSentence();
//Check if this sentence matches previous sentence
if (memcmp(SAVEDSENTENCE, COMPLETESENTENCE, sizeof(SAVEDSENTENCE))== 0)
{
FUNCTIONNUMBER[0]='9';
}
switch (atoi(FUNCTIONNUMBER))
{
case 0: Result();
break;
case 1: LoadingDots();
break;
case 2: UserInputResult();
break;
case 3: ChangeColor();
break;
}
double timeInterval;
for ( timeInterval = 0; timeInterval <= 900000000; timeInterval++);
}
while (q == 0);
}
I compile with g++ (should that make a difference).
Feel free to give some other tips on making the code less resource demanding.