Updated to remove fmod and string length warnings

This commit is contained in:
2019-03-11 13:07:03 -04:00
parent 0006517e74
commit 628cf67754
2 changed files with 20 additions and 20 deletions

View File

@@ -112,45 +112,45 @@ double getHourStopwatch(struct Stopwatch* timer){
//Gets the time from a stopwatch at the "Best" resolution. The goal is XXX.XXX [Resolution]
//While it would be possible to use this function to get the time while still running it is not recomended because of the time it takes to return the string
char* getStrStopwatch(struct Stopwatch* timer){
char* num = (char*)malloc(21 * sizeof(char)); //Holds the string that will be created in the end
char* num = (char*)malloc(35 * sizeof(char)); //Holds the string that will be created in the end
double dur; //Holds the duration the stopwatch has run
//Decide what the best way to get time is. Looking for a XXX.XXX format
if(getNanoStopwatch(timer) < 1000){
dur = getNanoStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d nanoseconds", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 35, "%d.%03d nanoseconds", intDur, fractDur);
}
else if(getMicroStopwatch(timer) < 1000){
dur = getMicroStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d microseconds", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 35, "%d.%03d microseconds", intDur, fractDur);
}
else if(getMilliStopwatch(timer) < 1000){
dur = getMilliStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d milliseconds", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 35, "%d.%03d milliseconds", intDur, fractDur);
}
else if(getSecondStopwatch(timer) < 1000){
dur = getSecondStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d seconds", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 35, "%d.%03d seconds", intDur, fractDur);
}
else if(getMinuteStopwatch(timer) < 1000){
dur = getMinuteStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d minutes", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 35, "%d.%03d minutes", intDur, fractDur);
}
else{
dur = getHourStopwatch(timer);
uint64_t intDur = dur; //Holds the whole number integer representation of the duration
uint64_t fractDur = (fmod(dur, 1.0) * 1000); //Holds the integer representation of the fractional part of the duration
sprintf(num, "%d.%03d hours", intDur, fractDur);
int intDur = dur; //Holds the whole number integer representation of the duration
int fractDur = ((dur - intDur) * 1000); //Holds the integer representation of the fractional part of the duration
snprintf(num, 21, "%d.%03d hours", intDur, fractDur);
}
return num;