Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 11 Jun 2011, 16:11
hi,
ist there already implemented a formatted DateTime string from clock?
Like this (just quick and dirty - but maybe it could be quicker and less dirty)^^:
Code: Select all
#define clock() (CurrentTick()-FirstTick()) // C-like
string gettimeofday(unsigned long lTime) {
int s1000, sec, min, hour, day;
string sTime;
s1000=lTime%1000;
lTime/=1000;
sec=lTime%60;
lTime/=60;
min=lTime%60;
lTime/=60;
hour=lTime%24;
lTime/=24;
sTime=StrCat(FormatNum("%d",lTime),"d ",FormatNum("%02d",hour),":",FormatNum("%02d",min),"'",FormatNum("%02d",sec),".",FormatNum("%03d",s1000));
return(sTime);
}
Code: Select all
TextOut(0, 8, gettimeofday(clock() ); // time since program start
(no month and year so far)
ps
how do I get a quote mark
"
into a NXC text string?
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 12 Jun 2011, 18:38
doc-helmut wrote: ist there already implemented a formatted DateTime string from clock?
I seriously doubt it.
[Under construction] I'll work on my implementation here:
Code: Select all
enum
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};
struct SYSTEMTIME {
unsigned long Year;
unsigned long Month;
unsigned long DayOfWeek;
unsigned long Day;
unsigned long Hour;
unsigned long Minute;
unsigned long Second;
unsigned long Milliseconds;
unsigned long prevGet; // Tick at last SYSTEMTIME_get() ???
};
SYSTEMTIME basetime;
SYSTEMTIME SYSTEMTIME_add(SYSTEMTIME a, SYSTEMTIME b)
{
a.Milliseconds = a.Milliseconds + b.Milliseconds;
a.Second = (a.Second + b.Second) + (a.Milliseconds / 1000);
a.Minute = (a.Minute + b.Minute) + (a.Second / 60);
a.Hour = (a.Hour + b.Hour) + (a.Minute / 60);
a.Day = (a.Day + b.Day) + (a.Hour / 24);
// ??? This should be exclusive ???
a.DayOfWeek = ;
// How many days in a month???
a.Month = ;
a.Year = (a.Year + b.Year) + (a.Month / 12);
// Shrink
a.Milliseconds %= 1000;
a.Second %= 60;
a.Minute %= 60;
a.Hour %= 24;
a.Day %= ????;
a.DayOfWeek %= 7;
a.Month %= 12;
// a.Year %= 0xFFFFFFFF; // Uh...
return(a);
}
SYSTEMTIME SYSTEMTIME_subtract(SYSTEMTIME a, SYSTEMTIME b)
{
}
void SYSTEMTIME_init(unsigned long Year, unsigned long Month, unsigned long DayOfWeek, unsigned long Day, unsigned long Hour, unsigned long Minute, unsigned long Second, unsigned long Milliseconds)
{
basetime.Year = Year;
basetime.Month = Month;
basetime.DayOfWeek = DayOfWeek;
basetime.Day = Day;
basetime.Hour = Hour;
basetime.Minute = Minute;
basetime.Second = Second;
basetime.Milliseconds = Milliseconds;
}
SYSTEMTIME SYSTEMTIME_get()
{
SYSTEMTIME stTemp;
stTemp.Milliseconds = CurrentTick();
stTemp = SYSTEMTIME_add(basetime, stTemp);
return(stTemp);
}
As you can see, I have no clue what I'm doing.
doc-helmut wrote: how do I get a quote mark
"
into a NXC text string?
What do you mean?
Last edited by
muntoo on 12 Jun 2011, 21:48, edited 4 times in total.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 12 Jun 2011, 18:50
nice to meet you :)
well as my time string questions seems to be answered -
with my 2nd question
how do I get a quote mark
"
into a NXC text string?
I meant: how do I get the quote mark
"
into a text string? :)))
if one wants to write the text string in C containing the double-apostrophe, e.g.
LAstory wrote: the traffic sign said "hug me"
usually one has to redouble it:
Code: Select all
string LAstory="the traffic sign said ""hug me""";
printf(LAstory);
but somehow I don't get that into a NXC string...
actually I tried that for another reason: I wanted to mark the minutes by a
' and the seconds by a
" :
12:34'18"
mattallen37
Posts: 1818 Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:
Post
by mattallen37 » 12 Jun 2011, 20:45
Can you flatten the number 34 (0x22)? That is the ASCII value of a >"<.
spillerrec
Posts: 358 Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:
Post
by spillerrec » 12 Jun 2011, 20:51
No, that is not how it is usually done. You normally do it like this:
Code: Select all
"the traffic sign said \"hug me\""
This works in NXC too.
I have never seen it done with "". I tried it in my C++ compiler and it compiles fine, however it treats it as two separate strings (there can even be spaces in between) and then simply joins them without the quotes.
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 12 Jun 2011, 20:53
how can I convert the character Flatten(34) to a string?
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 12 Jun 2011, 20:59
I have never seen it done with ""
hmmm: should that have been Pascal...?
but
works, thanks! :)
mattallen37
Posts: 1818 Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:
Post
by mattallen37 » 12 Jun 2011, 21:16
doc-helmut wrote: how can I convert the character Flatten(34) to a string?
Code: Select all
task main(){
string Text = Flatten(0x22);
TextOut(0, LCD_LINE1, Text);
while(true);
}
Flatten is the command I use to convert numbers (or arrays) into ASCII characters (or strings of them).
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 12 Jun 2011, 21:28
ok, I see, thank you!
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 12 Jun 2011, 21:47
More on escape sequences.
And, of course,
Microsoft loves doing things their own way.
In C++, the following are all equivalent:
Code: Select all
string text = "abcdefghijkl";
string text = "abcd"
"efgh"
"ijkl";
string text = "abcd\
efgh\
ijkl";
In Visual Basic, and a few other languages,
""
is the same as
\"
in C++.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange:
bit.ly/Area51LEGOcommit
Users browsing this forum: No registered users and 4 guests