![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C99-snprintf 1.1 (Default branch) | iBot | Software Releases - RSS News | 0 | 01-20-2008 04:50 PM |
| C99-snprintf 1.0 (Default branch) | iBot | Software Releases - RSS News | 0 | 01-06-2008 01:50 PM |
| problem with sprintf snprintf in Solaris | diganta | SUN Solaris | 7 | 12-24-2004 03:41 AM |
| Abnormal Termination errors | bialsibub | UNIX for Dummies Questions & Answers | 2 | 11-14-2001 07:21 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
does snprintf guarantee null termination?
Hi All,
I was reading the man page of snprintf function and it saids that snprintf adds a null terminator at the end of the string, but I remember once someone told me that snprintf doesn't guarantee the insertion of a null terminator character. What do you think? Does anyone have experience on it?? Thanks!! |
| Forum Sponsor | ||
|
|
|
|||
|
According to POSIX.1-2001:
"The snprintf() function shall be equivalent to sprintf(), with the addition of the n argument which states the size of the buffer referred to by s. If n is zero, nothing shall be written and s may be a null pointer. Otherwise, output bytes beyond the n-1st shall be discarded instead of being written to the array, and a null byte is written at the end of the bytes actually written into the array." |
|
|||
|
What the OP is on about:
from the same C-99 standard (what POSIX uses) Quote:
You should check return codes no matter how stupid it seems. If you use gcc then Code:
gcc -Wall <filename.c> |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|