|
You must use another variable for this purpose.
CString str, strTemp;
strTemp.Format(" qer23 %d asdgsgd", var);
str += strTemp;
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
or
str.Format("%s qer23 %d asdfgsf",str,var);
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
This approach won't work.
To quote from the MSDN documentation for CString::Format()
The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%s%d", str, 123); // Attention: str is also used in the parameter list.
will cause unpredictable results.
|
|
|
|
|
yeah sounds logical, coz its working on the same object, i assumed that a copy of the parameter would be made.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
If you are using VS.NET 2002 or later, the CString class includes the member function AppendFormat , which does what you are asking.
If you are using VC6, you will need to do something like this:
CString str,tmp;
str = ";kj;lak;sajlg";
tmp.Format(" qer23 %d asdgsgd", var);
str += tmp;
Software Zen: delete this;
|
|
|
|
|
Visual C++
a simple question!
what is the easiest way to add a simple vertical scroll bar to a dialog based project?
|
|
|
|
|
Override PreCreateWindow and add WM_VSCROLL as shown below:
cs.style |= WS_VSCROLL;
Hope this helps.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
Hello!
I'm newbie in C/ANSI programming.
I have another problem:
i have a char *c="word1 word2 word3";
how can I obtain the word in separate strings?
This is what I want to do:
char *c="word1 word2 word3";
char **words;
after proccessing the string c I want to have
words[0]="word1";
words[1]="word2";
words[2]="word3";
Thank you!
|
|
|
|
|
try looking up strtok(), sample usage in MSDN library.
INTP
|
|
|
|
|
Use strchr or strtok .
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
Hello!
I have another problem.
I want to make 2 programs a client and a server.
This programs must access the same file and read/write into it.
EXAMPLE:
if the client write to the file:
#CLIENT 1 REQUEST
the server must read this and response:
#S CLIENT 1 REPLAY
Now this is the problem:
I want to do this in client:
while (1)
{
read from file;
if string readed containt #S CLIENT 1
{
do some action
Ex: write to file #RESPONSE ACCEPTED
}
}
and I want that client to do this forever.
And I want the same to do the server.
Now How do I open/read/write to file?
Or how to do this?
Only ANSI/C code.
Thank You!
Bye!
|
|
|
|
|
Hi
The program that write the file have to make a fflush to write the data to the file otherwise the data is only in memory...
after that the other program can read de info...
|
|
|
|
|
I have a text file with reserved c words, one in each line. for example:
auto
asm
break
case
char
const
..(continues)
and i want to load all of them in a dynamic char matrix, to reserve memory for all the words in the first dimension, and then for the size of each word, so i declare:
char **palres;
first of all i go through the file once to know how many reserved words there are, and reserve memory:
<br />
i=0;<br />
while (!feof(archpalres))<br />
{<br />
fgets (temp,MAX_PAL,archpalres);<br />
i++;<br />
}<br />
cantpalres=i-1;<br />
palres = (char**) malloc ((sizeof(char*))*cantpalres);
then, i go to the beginning of the file, read the length of every reserved word, and i copy it in a temp string. with malloc i reserve memory and try to copy it in the char **palres, but i'm sure there's something i'm doing wrong, here's the code":
<br />
fseek (archpalres,0,SEEK_SET);<br />
<br />
j=0;<br />
while (!feof(archpalres))<br />
{<br />
i=0;<br />
<br />
c=fgetc(archpalres);<br />
while ((c!='\n') && (!feof(archpalres)))<br />
{<br />
temp[i]=c;<br />
i++;<br />
c=fgetc(archpalres);<br />
}<br />
temp[i]=0;<br />
<br />
*palres = (char*) malloc ((sizeof(char))*i);
<br />
for (k=0;k<=i;k++)<br />
{<br />
palres[j][k]=temp[k];<br />
}<br />
j++;<br />
}<br />
i think i'm not reserving memory in a good way with malloc. I tried checking with the debugger, but i don't understand what it says. It's the first time i use malloc for double (**) pointers.
Thanks!
|
|
|
|
|
Are you getting (compiler, linker, runtime) errors somewhere? What are you seeing in the debugger?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
i got it
thanks anyways!
the problem was this line:
*palres = (char*) malloc ((sizeof(char))*i);
it works with:
palres[j] = (char*) malloc ((sizeof(char))*i);
|
|
|
|
|
cantpalres=i-1;
palres = (char**) malloc ((sizeof(char*))*cantpalres);
cantpalres=i;
palres = (char**) malloc (sizeof(char*)*cantpalres);
i=0;
while (!feof(archpalres))
{
if( !fgets (temp,MAX_PAL,archpalres) )
break;
++i;
}
cantpalres=i;
palres = (char**) malloc (sizeof(char*)*cantpalres);
if( !palres )
return;
fseek (archpalres,0,SEEK_SET);
i=0;
while (!feof(archpalres))
{
if( !fgets (temp,MAX_PAL,archpalres) )
break;
pNewline = strchr(temp,'\n');
if( pNewline )
*pNewLine = '\0';
len = strlen(temp) + 1;
palres[i] = (char*) malloc (sizeof(char)*len);
if( palres[i] )
strcpy(palres[i],temp);
++i;
}
Normaly I would not have given a complete solution, but there was to much wrong too explane it all.
INTP
|
|
|
|
|
thanks mr Shaw!
this line you wrote were the answer. i didn't add 1, that's why it didn;t work
len = strlen(temp) + 1; //
|
|
|
|
|
Try (*palres) = (char*) malloc ((sizeof(char))*i); parles[j] will also work as you have found out. The problem is in the order of precedence. The brackets will solve this problem.
Dave
|
|
|
|
|
Does anyone know ofa mechansim to get thread timing information. I am trying to get a better understanding of the percentage of CPU utilization in a multi-threaded app, but on a per-thread basis as opposed to a per function basis.
The system APIs provide this info for processes, but I have been unable to get equivalent info for threads.
If someone can elighten me, or suggest a technique, I would appreciate it.
|
|
|
|
|
GetThreadTimes
Don't try it, just do it!
|
|
|
|
|
How to convert "N" to unicode 004E ?
CString n("N");
.
.
.
Output:
004E
Please help me!
|
|
|
|
|
input a unicode string: L"N"
Don't try it, just do it!
|
|
|
|
|
How to convert "N" to unicode 004E ?
|
|
|
|
|
for ANSI characters, the lower byte of its unicode representation is just the same as ASCII, while the higher byte is always 00.
So, since 'N' in ASCII is 0x4E, Unicode 'N' is 0x004E (it might be 0x4E00, depending on big endian or little endian).
|
|
|
|
|
Hi everyone,
I'm trying to get at the mouse position in a list view but am having no luck. I have 1 column which displays a series of small icons (ie within a single subitem of the list) and I need to be able to tell which icon has been clicked. Screen real-estate prevents me from doing this using a separate sub-item for each icon.
I'm picking up the NM_CLICK message but there seems to be no MouseMove message available in a ListView control. I only get them in the view when I use SetCapture() but I don't know how I can do a ReleaseCapture() - is there a way of receiving a message when the mouse leaves the control's borders?
Many thanks in advance.
Simon
|
|
|
|