Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backslash interpreted incorrectly

Status
Not open for further replies.

Malachi

Programmer
Aug 13, 2001
38
US
I used the backslach character to perform line continuation in the MSVC++ V6.0 IDE. After Auto-formating the text a number of extra spaces were added to the string literal. I'm trying to create an array to pass to the OPENFILENAME structure in order to present the user with a list of files to choose from. The extra spaces hork up the file list strings.

Here is how I'm defining my string literal array for the OPENFILENAME.lpstrFilter. This looks pretty much like it does in the MSVC++ IDE after formatting the code using the ALT-F8 key combo.

Code:
static SCHAR TxtFilters[] = "							   Text File (*.TXT)\0*.TXT\0							   List File (*.LST)\0*.LST\0							   OCR Reject(*.REJ)\0*.REJ\0							   OCR Flags (*.FLG)\0*.FLG\0							   OCR/ICR   (*.VIK)\0*.VIK\0							   All Files(*.*)\0*.*\0							   \0\0";

Is this a bug in the editor or my array definition syntax?
 
I don't know why the ALT-F8 sets it up like that but in order for the \ to work like that you need to make sure everything on the next line has NO preceding characters. Push all that to the front of the next line and it should work fine.

However, I will say that the \ character like that is used mainly for preprocessor definitions and using it like that can make your code quite confusing and unreadable since you cannot use the tabs at all on the subsequent lines. Just something to think about.

-Skatanic
 
Thank you very much for the reply. I should have mentioned that the code I'm working with is legacy code, and is wrought with string literal definitions like the one I mentioned.

The code works well if each line in the string literal has NO preceding characters. However, if the auto-format feature is used the string is moved over, I guess to make it more readable, and the spaces are introduced. In any case, the compiler doesn't complain, even though by definition the lpstrFilter shouldn't contain any spaces.

I'm not sure what you mean by saying the \ character is mainly used for preprocessor definitions. The backslash character is used in various ways within the C language. ANSI C and traditional C interpret the backslash at the end of a line as a line continuation character. Migrating legacy code to MSVC++ 6.0 becomes a real headache when little things like this pop up.

I also don't understand what is mean when you reply "you cannot use the tabs at all on the subsequent lines".

Is there a way to tell the auto-format utility to ignore backslash characters when they appear at the end of a quoted string literal?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top