C Escape Sequence Like "\n" Doesn't Function When Passed to C (42857)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0

This article was previously published under Q42857

SUMMARY

When CALLing a C function from QuickBasic and passing a C-format string that contains C escape sequences, the escape sequence does not execute, but rather displays as part of the string. When the following example is used, the C "\n" escape sequence for carriage return/linefeed will not be executed from the C function as expected; the "\n" will simply be displayed as part of the string:
   FORMAT$ = "number1= %d   number2= %d\n" + CHR$(0)
   CALL CROUTINE(SADD(FORMAT$),LEN(FORMAT$)
				
This information applies to QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b, and to Microsoft Basic PDS Version 7.00.

MORE INFORMATION

Escape sequences, such as "\n", are replaced with the carriage return/linefeed characters when the C code is compiled. Therefore, if they are passed to a C program at run time, "\n" is not recognized as anything more than part of the string to be displayed.

For the C program to execute an escape sequence passed to it from a QuickBasic program, the actual characters for the desired operation must be appended to the passed string, as in the following example:
FORMAT$ = "number1= d%   number2= d%" + CHR$(13) + CHR$(10) + CHR$(0)
CALL CROUTINE(SADD(FORMAT$),LEN(FORMAT$)
				
This passes the carriage return/linefeed sequence to the C function.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB42857