Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fixing C

Name: Anonymous 2014-04-09 15:55

How to fix C?
What don't you like in C?

I do not like the many useless types while we could just define our own n-bit integer
also a a better typesystem for compile time checking would be nice
I also would like pure functions that I would be able to use outside of functions just like I do in macros

no sageposting allowed

Name: Anonymous 2014-04-11 17:48

/prog/, I'm an expert coder. Please rate my C/C++ codes...


string modify( const string & str )
{
if( str.size() == 0 ) return "00";
if( str.size() == 1 ) return "0" + str;
return string( str.end() - 2, str.end() );
}

string modify4( const string & str )
{
if( str.size() == 0 ) return "0000";
if( str.size() == 1 ) return "000" + str;
if( str.size() == 2 ) return "00" + str;
if( str.size() == 3 ) return "0" + str;
return string( str.end() - 4, str.end() );
}

string TimeISOFormat( time_t cur )
{
char buf[32];
struct tm * timeinfo;
timeinfo = localtime ( &cur );
strftime(buf, 32, "%y", timeinfo);
string year(buf);
strftime(buf, 32, "%m", timeinfo);
string month(buf);
strftime(buf, 32, "%d", timeinfo);
string day(buf);
strftime(buf, 32, "%H", timeinfo);
string hour(buf);
strftime(buf, 32, "%M", timeinfo);
string minute(buf);
strftime(buf, 32, "%S", timeinfo);
string second(buf);
return modify4( year ) + "-" + modify( month ) + "-" + modify( day ) + "T" + modify( hour )+ ":" + modify( minute )+ ":" + modify( second );
}

string CurrentTimeISOFormat()
{
time_t cur = CurrentTime();
char buf[32];
struct tm * timeinfo;
timeinfo = localtime ( &cur );
strftime(buf, 32, "%y", timeinfo);
string year(buf);
strftime(buf, 32, "%m", timeinfo);
string month(buf);
strftime(buf, 32, "%d", timeinfo);
string day(buf);
strftime(buf, 32, "%H", timeinfo);
string hour(buf);
strftime(buf, 32, "%M", timeinfo);
string minute(buf);
strftime(buf, 32, "%S", timeinfo);
string second(buf);
return modify4( year ) + "-" + modify( month ) + "-" + modify( day ) + "T" + modify( hour )+ ":" + modify( minute )+ ":" + modify( second );
}

time_t CurrentTime()
{
time_t rawtime = 0;
time(&rawtime);
return rawtime;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List