|
What you want to do is:
char StringData[11];
memcpy(StringData, StringBuf, 10);
StringData[10] = '\0';
Anyway, the proper way to handle strings in C++ is to use std::string class, and not to hack with char*
I vote pro drink
|
|
|
|
|
strncpy does not insert a null. You have to do that manually. I think that is one we've all been bit by at some time. Nemanja's advice is your best alternative.
"Thank you, thank you very much" Elvis.
|
|
|
|
|
This is what I ended up doing before I tried Nemanja's advice...which by the way was the best advice.
StringBuf[11] = 0x00;
strcpy(StringData, StringBuf);
but I still got garbage in the front of the string that I wanted.
After switching to Nemanja's advice it worked great.
Thanks everyone.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
StringBuf[11] = 0x00;
strcpy(StringData, StringBuf);
but in your first post, you were doing it the other way round...
a handy mnemonic to remember is that strcpy and strncpy are layed out like an equals command:
a="hello ";
b="world";
strcpy(a,b);
and noone complain that that code doesnt work, it was an example of a point and it's not really necessary to allocate memory for a concept
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
If you must use C strings, then you should do this:
char StringBuf[32400];
memset(&StringBuf, 0, 32400); // I *think* I have the parameters in the right order
Now your string is FULL of NULL, so whatever you copy into it will be NULL terminated.
It's better to use std::string, or you can use CString if you need to convert to wide strings at any point. Then you get operator =, and the strings will resize themselves to take up as much room as you need, and no more.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I have a NT Service (usually runs on Win2K AS), that accepts requests on sockets, process them, and return a response.
We noticed, using Task Manger, that the service had nearly 50,000,000 page faults (after processing around 500,000 requests). Is this normal? If it is not, what could be the cause?
Tx
Michel
P.S.: The service operations don't seem to be affected.
|
|
|
|
|
Sounds like you need more RAM.
Jon Sagara
What about ?
|
|
|
|
|
I want to use some .Net features like GDI+ or some namespace we use in c#,
in VC++.Net,I don't know how ,any suggestion or article or..?(should I import their dll into my project?)
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
Mazdak wrote:
I want to use some .Net features like GDI+ or some namespace we use in c#,
in VC++.Net,I don't know how ,any suggestion or article or..?(should I import their dll into my project?)
Check out these articles in the .NET section.
http://www.codeproject.com/dotnet/
See Christian Graus's articles on GDI+. Those were of help in getting me started. Just don't confuse POINT with Point and RECT with Rect (That gets me every time).
|
|
|
|
|
Thanks ,It is very useful
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
Jay Beckert wrote:
See Christian Graus's articles on GDI+.
They're going to start up again now that I have a new job. Too bad it's probably a bit late now, but I'm going to do a series on image processing.
Jay Beckert wrote:
Those were of help in getting me started. Just don't confuse POINT with Point and RECT with Rect (That gets me every time).
I don't get why Color is the only class with built in conversion to the old types, if I were to write Rect, operator RECT is the third thing I would include ( after copy constructors and operator=).
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I thought you were on holiday? You're working way too hard.
Congrats again on the new job.
Jon Sagara
What about ?
|
|
|
|
|
Jon Sagara wrote:
Congrats again on the new job.
Thanks - I'm really stoked. Yes, I am on holiday, but I can't do without my dose of CP every day. Plus I'm on cable here, so I'm downloading lots of videos....
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
They're going to start up again now that I have a new job. Too bad it's probably a bit late now, but I'm going to do a series on image processing.
Nah, never to late and I'll surely be waiting for the series. I just love all the options that are available in GDI++, though I think maybe they made it to easy. Maybe I'm a control freak.
Christian Graus wrote:
I don't get why Color is the only class with built in conversion to the old types, if I were to write Rect, operator RECT is the third thing I would include ( after copy constructors and operator=).
You think? Just when I get confortable with doing it this way, i have to get used to it another way. The conversions would of been nice.
|
|
|
|
|
Jay Beckert wrote:
I just love all the options that are available in GDI++, though I think maybe they made it to easy. Maybe I'm a control freak.
I agree - I am VERY glad I learned to do all the stuff GDI+ does 'by hand' before GDI+ came along and started doing it for me.
Jay Beckert wrote:
You think? Just when I get confortable with doing it this way, i have to get used to it another way. The conversions would of been nice.
I'm sorry you misunderstood me - I am saying the same thing, I said the 'third thing' only because I would always write the copy constructor and operator= for a class before pretty much anything else. I thought if I said 'first thing' as a turn of phrase someone might ask me why
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
I'm sorry you misunderstood me - I am saying the same thing, I said the 'third thing' only because I would always write the copy constructor and operator= for a class before pretty much anything else. I thought if I said 'first thing' as a turn of phrase someone might ask me why
I understood you Christian. I think I confused you; I said "You think?" as in you would think they added the conversions just as Color. Sorry about that. I'll point at some one else and say we're with them. Hows that?
|
|
|
|
|
I'm looking for a way of taking an image file (bmp, gif or jpeg) and displaying or printing it with the same sort of quality that MS Word produces when the image has to be strected or shrunk. MS Word does some sort of dithering to make the edges fuzzy, whereas most stretch routines just lose/gain solid pixels.
Anyone got any code to do this or can suggest something?
Thanks,
Keith Worden
|
|
|
|
|
This looks like it might work for you:
Two Pass Scaling using Filters
farewell goodnight last one out turn out the lights Smashing Pumpkins, Tales of a Scorched Earth
|
|
|
|
|
For image display, I found in the past that <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_76if.asp">DrawDibDraw</a> does a fairly good job (smooth scaling, dithering...)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
I do not know how to create a String , I'd like to do something like
String s = new String("hello");
and I'd like also to know how to compare 2 strings
thanks
Pierre
|
|
|
|
|
Look up the class CString in MSDN.
Jon Sagara
What about ?
|
|
|
|
|
Use the Class CString and the function method Compare or CompareNoCase....
CString str = _T("Hello");
if(str.Compare("Hello") == 0)
{
AfxMessageBox("Equal");
}
Regards
APATHY ERROR: Don't bother striking any key. Application has reported a "Not My Fault" in module KRNL.EXE in line 0200:103F
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Perhaps this question has been asked before but I could not find it.
How can I get the netbios name of a computer in my lan if I only know its ip number ?
Orcun Colak
|
|
|
|
|