devxlogo

Tip Bank

If Your Compiler Doesn’t Support snprintf() Yet

Sometimes, sprintf() is unavoidable. For example, when compatibility with C is paramount, Sprintf() has a safer version called snprintf(), which doesn’t write past its buffer’s limits. However, because snprintf() was

Avoid This Common ASSERT(…) Mistake

ASSERT is a very helpful macro for debugging, because it helps root out false assumptions. However, many programmers make the mistake of putting actual assignments inside the macro. Consider the

Using const_cast

If you want to convert from a const to a nonconst or from a volatile to a nonvolatile, you can use const_cast. This is the only conversion allowed with const_cast.

Porting Code With Unix File I/O

In pre-standard C, I/O operations were based on the Unix APIs. Instead of FILE pointers and functions such as fopen(), fread(), and fclose() that are defined in the header, Unix

Rounding a Number

The Standard Library doesn’t have a function for rounding floating point variables. However, you can easily round numbers as follows: double d=42.666;int rounded=d+0.5; // rounded = 43d=rounded; // d is

JToolTip in a JTable Column

Tool tips are handy for providing explanations for buttons and other fixed components in a panel. Sometimes, it

Execute an External Program Without Using JNI

The secret lies in the Runtime class. Runtime contains the methodexec, which takes the basic form of: Process exec(String command) orProcess exec(String[] comdarray) orProcess exec(String[] cmdarray, String[] envp, File dir)

Reading From and Writing To a URL

A typical HTML page might contain text fields to send data to the server. The data is submitted by clicking the submit button on the Web page. The browser then