|
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
|
|
|
|
|
NM_CLICK messages from a ListView are accompanied by an NMLISTVIEW structure. You can cast the NMHDR pointer to this type, e.g.
void CMyClass::OnListViewClick( NMHDR * pNotifyStruct, LRESULT * result )
{
NMLISTVIEW* pnmlv = (NMLISTVIEW*) pNotifyStruct;
} The NMLISTVIEW structure contains a member ptAction which tells you where the user clicked. I can't remember if this is in screen or client co-ordinates; you may need to use ScreenToClient to convert.
From here you can use GetSubItemRect and work out the relative position of the click within the subitem.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks very much Mike, this was exactly what I was looking for.
Simon
|
|
|
|
|
I like to change Edit Focus when I tap "Return" Key.
The problem is that I can't catch VK_RETURN within CEdit::OnKeyDown() event.
|
|
|
|
|
Does the edit control have the ES_WANTRETURN (multiline scope?) style?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Yes the edit control have the ES_WANTRETURN style,
But the probleme is that the dialog is closed when I press "ENTER", et usually I can't catch the VK_RETURN wthin Edit::OnKeyDown().
|
|
|
|
|
amine.turki wrote:
But the probleme is that the dialog is closed when I press "ENTER"...
If the edit control has focus when you press the Enter key, the dialog should not be closing. If it is closing, then either the edit control does not have focus, or it does have focus but it does not have the ES_WANTRETURN style.
See if this discussion helps.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You could override the PreTrandlateMessage for the controlling window and do this:
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
// check to see if we need to tab between edit controls
Cwnd *pWnd = GetFocus();
if (pWnd != NULL)
{
if (pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
{
// tab instead of return
pMsg->wParam = VK_TAB;
}
}
}
// fall through to normal processing
This will change return key presses into tabs for edit controls only.
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
If you're subclassing the edit control, you could try handling WM_GETDLGCODE and returning DLGC_BUTTON . AFAIK, the ES_WANTRETURN style only matters if it's a multi-line edit control.
How do you move in a world of fog, That's always changing things?
Makes me wish that i could be a dog, When i see the price that you pay.
|
|
|
|
|
Hi,
I have a Modal Dialog Box, When i click the minimize bar on the top right corner, It does not go to the task bar, instead it settles at the bottom left corner of the screen, what should I do to make it settle in the taskbar ?
Thanks,
Deepak Samuel.
|
|
|
|
|
are u using MFC or simple win32?
Don't try it, just do it!
|
|
|
|