|
George_George wrote: What means "plain not safe"?
This is what I had in mind:
char buffer[1];
sprintf(buffer, "The number is %d", 42);
This code will result in a buffer overrun which at best will crash the program and at worst will open up a security flaw will can be exploited.
Steve
|
|
|
|
|
Thank you Steve!
Maybe I have not made myself understood. My question is not whether the buffer (as the 1st parameter) is large enough (suppose it is large enough in this case, I agree with you about the setbacks of this method), my question is that whether I can input char* (non-unicode type) as the 3rd parameter, while the 1st parameter is wchar_t* type and the 2nd parameter is L (constant string) type.
regards,
George
|
|
|
|
|
Yes. Use %S instead of %s .
Steve
|
|
|
|
|
Thanks Stephen,
I have found that %S is used to specify a wide-character string. Could you show me an example of mixed using of unicode type and non-unicode type, in the following format -- without any errors to print out anything?
I just can not imagine why we can mix the use of unicode type (w_char* and _T) and non-unicode type (char*).
_stprintf (wchar_t*, _T"%s", char*)
regards,
George
|
|
|
|
|
|
Thanks Michael!
Suppose that UNICODE macro is define and we can pass char* type parameter to _stprintf? I can not imagine that -- I think it is not safe. Could you show me an example please to show it works to pass char*?
regards,
George
|
|
|
|
|
Now that I looked more closely at your question I see where the confusion is coming from. %s means a string of TCHAR s, so that will change between ANSI and Unicode builds. The ... in a parameter list means "any number of parameters of any type" - it's totally unrelated to the character set you're building with, but the format string does have to take character sets into account:
TCHAR sz[100];
_stprintf(sz, _T("Hello %hs"), "Bob"); Note that I used %hs to mean an ANSI string.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Thank you Mike!
If UNICODE is defined, then in your above example, TCHAR will be wchar_t, _T will be defined as L and "Bob" will still be char* type (non-unicode type). Is that correct?
I am not sure whether your above example will still work if UNICODE is defined since you print a non-unicode type (char*) to a unicode type _T. If your example works, could you show me please?
regards,
George
|
|
|
|
|
|
Hi Mike,
If I correctly understand, you mean debug into sprintf? C runtime library is not an open source provided by Microsoft.
regards,
George
|
|
|
|
|
Hi,
I know the ISO-9660 file format but I'm unble to generate IS0-9660 file system...I don't want to use any CD writing tools or other ISO creation tools for the creation of iso file ie, I have to write the code in vc++ for creating iso file...
Please specify the sites where I'll get the source code or suggest me for the creation of iso file
I'm eagerly waiting for ur valuable suggestions...
Regards,
nag.
|
|
|
|
|
http://vaporcd.sourceforge.net/index.html
Hope that help.
|
|
|
|
|
Hi nguyenvhn,
I'm thankful for ur prompt response...Vaporcd creates the .iso file by reading CD...But I should create the .iso file for any file ie, If i have text file, it should be created as .iso file... It shouldn't be done through drivers as Vaporcd
has done...
I'm waiting for ur response...
Regards,
nag..
|
|
|
|
|
I am invoking an an MFC exe (inside initinstance () if i put cout<< statement , nothing is reflected in dos winndow.Please if you have any suggestions tell me.
|
|
|
|
|
The application that uses cout should be a console based application(uses main not winmain ) otherwise it won't show up.
|
|
|
|
|
memory for reference variable will be allocated or not?
if yes,where does the reference variable get
stored( stack or heap)?
Thanks in advance.
Prashanth.v
-- modified at 3:07 Wednesday 3rd May, 2006
|
|
|
|
|
What do you mean exactly ? Post some code to illustrate your question.
|
|
|
|
|
this question asked me in interview.
i donot have any code.
question is
where does the reference variable get
stored(stack or heap)?
Prashanth.v
|
|
|
|
|
a reference is nothing more than a dereferenced pointer.
when you create a reference variable, you create a variable first (before looking at its type), so the program NEED to store it somewhere in memory to keep its information.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Isn't this an implementation detail?
For example
int a = 10;
int &b = a;
The compiler doesn't have to have memory for b, it can get the appropriate memory location from the symbol table. Of course when not possible to implement in this way compilers use a pointer to implement the reference.
|
|
|
|
|
solution please.
whether it gets stored in stack or heap?
|
|
|
|
|
Unfortunately I think you should have clarified in the interview what was meant by reference variable.
Say you had code like
int a = 10;
int &b = a;
In this case it's not stored anywhere. The compiler just knows what you are referring to.
If you had a function that looks like say
DoSomething(int &b);
int a = 10;
DoSomething(a);
Then the compiler has to implement the reference as passing a pointer to 'a' on the parameter list. Say this calling convention passes all arguments to functions on the stack, would this be considered storing in the stack?
|
|
|
|
|
no memory is allocated to a reference variable.
not in stack nor in heap.
|
|
|
|
|
my application needs us to display active users in the network
can anyone help me wiht some ideas or codes
mad john
|
|
|
|
|
hi,
use the NetUserEnum(...) Api you can list all the Users in a Perticular Domain.
Hope this will be usefull to you.
good luck,
uday.
uday kiran
|
|
|
|