|
int iCount = 0;
int i;
iCount = m_payeelist.GetSelCount();
if (iCount <= 0) return ;
int* pItems = new int [iCount];
m_payeelist.GetSelItems(iCount, pItems);
CStringList StrList;
for (i=0;i<m_payeelist.GetSelCount();i++)
{
char *pStr=new char[10];
m_payeelist.GetText (pItems[i],pStr);
StrList.AddTail(pStr);
delete pStr;
}
See if this helps
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 10:38 Tuesday 13th June, 2006
|
|
|
|
|
It works this way too. I never seem to understand how to work with char correctly.
Thanks.
Fortitudine Vinsinues!
|
|
|
|
|
Hello everyone!
This is what I want:
fileName : is730enu.exe.mtx [Correct]
unexName : is730enu.exe [Adds 4 more chars at end]
partName : is730enu.exe.000 [Same as above, but with .000 ext]
How could I do that? Like, I want to remove the last 4 chars from fileName and add that to unexName, but then add the .000 extension on the 4 chars left, but it just adds it after... I don't get it, how can it add it if I have the string on a fixed size? Thanks!
<br />
char *partName, *unexName;<br />
<br />
<br />
unexName = malloc(strlen(fileName) - 4);<br />
strncpy(unexName, fileName, strlen(fileName) - 4);<br />
<br />
<br />
partName = malloc(strlen(fileName));<br />
partName = mtxSplitAddExt(unexName, part);<br />
<br />
return partName;
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Any reason why you can't use std::string?
You have a memory leak for unexName and you have delegated responsiblity to the caller to free partName.
|
|
|
|
|
hfry wrote: Any reason why you can't use std::string?
It's regular C.
hfry wrote: You have a memory leak for unexName and you have delegated responsiblity to the caller to free partName.
So... What can I do about it? Thanks! (Sorry if I sounded n00bish, but I am after all... )
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
-- modified at 10:26 Tuesday 13th June, 2006
|
|
|
|
|
Your problem:
a) strlen returns the length of the string WITHOUT null-termination.
leads to
b) you are allocating only enough memory for the "text", not for the terminator.
and
c) strncpy realizes that there is not enough room for the null-terminator (remember, strncopy copies AT MOST n characters - including the null terminator. If you had used strcpy, you would instead have written outside your allocated memory.
Solution: use (strlen(input)+1) for mallocing and strncpy.
Cheers,
Sebastian
Note: Before someone shouts "but the mtx extension is only 3 characters", let me add: there is a dot in there as well.
--
Contra vim mortem non est medicamen in hortem.
-- modified at 10:45 Tuesday 13th June, 2006
|
|
|
|
|
If there is a malloc, there must be a free. And you shouldn't return a pointer to a C string that you allocated on the heap as it's not usually obvious to the person using your function that it's a string that he must free.
I'd probably do something like this..
int getpartname(char *filename, char *partname, size_t partnamesize)
{
int dot = -1;
int filenamelen = strlen(filename);
int pos;
for(pos = filenamelen; pos >= 0; pos--)
{
if(filename[pos] == '.')
{
dot = pos;
break;
}
}
if(dot == -1) return -1;
if(partname == 0 || partnamesize < dot + 4 + 1)
{
if(partnamesize != 0) partname[0] = '\0';
return dot + 4 + 1;
}
strncpy(partname, filename, dot);
partname[dot] = '\0';
strcat(partname, ".000");
return 0;
}
The person using your function would have 2 options
char partname[80];
getpartname("is730enu.exe.mtx", partname, sizeof(partname));
char *partname;
int len = getpartname("is730enu.exe.mtx", 0, 0);
partname = (char*) malloc(len);
getpartname("is730enu.exe.mtx", partname, len);
: :
free(partname);
Oh, and just a friendly warning about strncpy...
http://blogs.msdn.com/oldnewthing/archive/2005/01/07/348437.aspx[^]
|
|
|
|
|
You should be able to use _splitpath and _makepath for this (not sure how it will handle the double extensions, but it should be okay).
Alternatively, you can copy the string to a new string and use strtok to parse the string and then reinsert the '.' where necessary.
For performance, if you don't need the middle name for anything, you could just replace the original characters with your new ones.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: not sure how it will handle the double extensions...
Everything after the rightmost dot is considered the extension. All else, including additional dots, is considered the base name.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
That is what I thought, but I hadn't tried it with those types of filenames.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
<br />
strncpy(unexName,filename,strlen(filename)-4);<br />
unexName[strlen(filename)-4]='\0';<br />
strcpy(partName,unexName);<br />
strcat(partName,".000");<br />
printf("\n%s",partName);<br />
Try this and tell me if it worked.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
Crap... I'm not getting this at all... Doesn't free ing make the string NULL ? How can I return/pass a null string? The only reason I'm using malloc() is to make the char* long enough to contain the other one... And, if I allocate only a certain amount of memory for a string, and I try to add something that's larger than that, why does it add it anyways without crashing? C is confusing... I'd be using C# if this app didn't require to work on DOS. But, hfry, why parse the file myself if the extension is always 3 chars? (plus the dot) Thanks you all!
And: VuNic, that code crashed Winders.
[edit] A few minutes later...
Now I really AM confused. If I only copy 8 characters, look at what I get:
is730enucrosoft é
...crosoft? Why is Microsoft involved here?! I got no "Microsoft" string in my whole freaking program!
But if I copy 9:
is730en
I have never been so confused in my life...
[/edit]
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
-- modified at 13:49 Tuesday 13th June, 2006
|
|
|
|
|
Exactly what is wrong with the code that I have provided?
The point is you shouldn't pass the pointer out, instead the caller should pass a buffer in. The caller has an option of creating a buffer on the heap or on the stack. If the caller creates the buffer on the heap using malloc, then he would also know that he has to free it.
Extensions are not always 3 characters.
I try to add something that's larger than that, why does it add it anyways without crashing
There is no reason why writing past an allocated buffer must cause a crash. It largely depends on what you happen to be writing over. If you are writing past an allocated buffer on the heap, fun things might happen in totally unrelated portions of your application that happen to be using that memory that you overwritten.
|
|
|
|
|
hmm.. well Kixdemp, I had to leave office fast and didn't read your problem well, I gave that answer with a rough Idea of your problem. Dont worry today I'll sit down for it. You would be able to do it certainly
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
hfry wrote: The point is you shouldn't pass the pointer out, instead the caller should pass a buffer in. The caller has an option of creating a buffer on the heap or on the stack. If the caller creates the buffer on the heap using malloc, then he would also know that he has to free it.
Oh... Now I understand why it's always done that way... Now, is that the source of the problem or can I leave that change (all my functions do it the other way...) for when I finish the program?
hfry wrote: Extensions are not always 3 characters.
In this program they are (*.mtx and *.000 thru *.fff)
VuNic: Alright!
Thanks you both!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Hi,
I am using Excel automation to plot the chart.I am not able to get a handle on the X-axis (primary), I already have a handle on the Chart (Because I can change the title/plot chart), I am trying to change X-axis property to Catagory(we can set X-axis to Automatic/Catagory/Time-Scale) using the following spinets
Axes axes;
lpDisp = chart.Axes( COleVariant((short)(2)), 1);
ASSERT(lpDisp);
axes.AttachDispatch(lpDisp);
////////////////Second way-------------------------
Axis axis;
lpDisp = axes.Item(2, 1);
ASSERT(lpDisp);
axis.AttachDispatch(lpDisp);
Does anyone know what I'm doing wrong?
Mike
|
|
|
|
|
Dears Sirs;
How can I make a color to my Formview
I learn my self
|
|
|
|
|
Talking in terms of VC7.0 or VS6.0?
In vc7.0 it's very easy just open the form view. Go to properties > Appearance >Backcolor and select your choice of color.
In am answering in the context because you asked for FormView
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 10:02 Tuesday 13th June, 2006
|
|
|
|
|
I am using Visual c++ PLease
|
|
|
|
|
Supposing you have an MFC application, I think you have to handle the WM_ERASEBKGND notification. Add a handler for this message in your frame class. Within the handler you will have a CDC object as a parameter. Use drawing functions to fill the frame with colour you prefer.
|
|
|
|
|
I don't see this handle : WM_ERASEBKGND
|
|
|
|
|
you can use WM_PAINT and use CPaintDC dc(this);
whitesky
|
|
|
|
|
Hi,
I m using Windows Timers in my application which has 4 threads. I need a separate timer for each thread. At most how many timers can I use in an application as in future I will update my application for 32 threads? Regards
Cyber Friend
|
|
|
|
|
Cyber Friend wrote: At most how many timers can I use in an application as in future I will update my application for 32 threads?
I'm not exactly sure. In any case, they are a limited resource. Check SetTimer() 's return value.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The Following link have more about Timers which may resolve your problem for creating timers and limit for creating them.
Timers[^]
Knock out 't' from can't,
You can if you think you can
|
|
|
|