Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

nul terminated string

gelarimer
Beginner
734 Views

I use the nul terminated string szfilebuffer inthe win32 function WriteFile(), and it appears to work OK, note however only 3 spaces are allowed (Buffer_Len-2:Buffer_Len) for ' 'C. When the file is written the Cr and Lf work fine, and I checked the location of the nul char and it is in char position Buffer_Len, exactly where it should be.

szfilebuffer(Buffer_Len-2:Buffer_Len) = ' 'C

The string ' 'C should require 5 spaces including the nul char as follows:

szfilebuffer(Buffer_Len-4:Buffer_Len) = ' 'C

I do not understand why3 spaces work for ' 'C?Any insight would be appreciated. Thanks.

0 Kudos
2 Replies
anthonyrichards
New Contributor III
734 Views

Because the C-string' 'C is visible to the compiler, the compiler preprocesses the string and inserts the correct control characters in place of the ' ' and the ' ' at compile time. If you had built your string using ''//'r'//''//'n'//''C, you will find that you get a string 5 characters long (including the null) and you would not get the control characters you want, because the compiler cannot recognise the ' ' string as a unit because it is not visible as a unit.

0 Kudos
gelarimer
Beginner
734 Views
Thankyou for the explanationand interestingexample about''//'r'//''//'n'//''C not producing the results desired.
0 Kudos
Reply