I have a working code using OPENFILENAME. May i know how to use strcat to dynamically control the its parameters
this one is working
//ofn.lpstrFilter = "Rule Files (*.net and *.rul)\0*.rul;*.net\0";
char filter[100];
char filterText[100];
char filterVal[100];
strcpy(filterText, "Rule Files (*.net and *.rul)");
strcpy(filterVal, "*.rul;*.net");
I tried using strcat first with ‘\0’ but it only only shows like this
strcat (filter, filterText);
strcat (filter,"\0");
strcat (filter,filterVal);
strcat (filter,"\0");
ofn.lpstrFilter = filter; \\missing \0
And I tried using ‘\\0’
strcat (filter, filterText);
strcat (filter,"\\0");
strcat (filter,filterVal);
strcat (filter,"\\0");
ofn.lpstrFilter = filter; \\now includes the\0
but when i run the program the dialogue box filter shows like this
“Rule Files (*.net and *.rul)\0*.rul;*.net\0”;
thanks
Using
"\\0"won’t do anything useful, that will just put the literal two characters\0in your string when you want a nul byte. However, strings in C are terminated by'\0'so you can’t usestrcatto construct a nul delimited string without a bit of pointer arithmetic.So, given these:
You’ll need to do something like this:
A better approach would be to allocate your
filterwithmallocso that you don’t have to worry about buffer overflows: