Custom function isn't working
#1

pawn Code:
stock GetTimeEx(&Hour, &Minute, &Second)
{
    gettime(Hour, Minute, Second);
    new s[3], m[3];
    format(s, sizeof(s), "%d", Second);
    format(m, sizeof(m), "%d", Minute);
    if(strlen(s) == 1)
    {
      new Second2[3];
      format(Second2, sizeof(Second2), "0%d", Second);
      Second = strval(Second2);
    }
    if(!strlen(s))
    {
      new Second2[3];
      format(Second2, sizeof(Second2), "00");
      Second = strval(Second2);
    }
    if(strlen(m) == 1)
    {
      new Minute2[3];
      format(Minute2, sizeof(Minute2), "0%d", Minute);
      Minute = strval(Minute2);
    }
    if(!strlen(m))
    {
      new Minute2[3];
      format(Minute2, sizeof(Minute2), "00", Minute);
      Minute = strval(Minute2);
    }
}
I made it because I was annoyed that if the time was for example 14:02:05 gettime would say 14:2:5. Do I need to return something at the end?
Reply
#2

You dont need such a complicated function for that.. >_<
Code:
format(str, sizeof(str), "Time: %02d:%02d", hour, minute);
Reply
#3

Then if the time were 14:43:15 for example you would get 14:043:015. Otherwise I would've done that.
Reply
#4

Quote:
Originally Posted by biltong
Then if the time were 14:43:15 for example you would get 14:043:015. Otherwise I would've done that.
Nope, it will always format two numbers.
Reply
#5

Yup, %02d is two numbers, %03d three numbers etc.
Reply
#6

Ok, but then why does it not change anything?
Reply
#7

The code below prints time 14:02:05, so I dont know what you're doing wrong.. post the code.
Code:
printf("%02d:%02d:%02d.", 14, 2, 5);
Reply
#8

I didn't put the 2 in >.<
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)