|
Something like this should work:
1) Point to the next-to-last character in the string
2) Compare two characters in string to "MJ" (memcmp )
3) If they match, break
4) Move pointer two places to the left
5) Go to step 2
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I think:
4) Move pointer one place to left
is better.
old 6502 coder
|
|
|
|
|
Thanks!
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
StrRStrI will return the last pointer to last occurance of "MJ" string.
|
|
|
|
|
We have a ISAPI from a third-party company running on Windows 2000 Server, the same ISAPI isn't running on Windows Server 2003, do you have any information about ISAPI incompatibility with Windows Server 2003 ?
Thanks for any tip.
GuimaSun
www.nexsun.com.br
NEXSUN TechZone
|
|
|
|
|
I'm writing an application that requires some BCH ECC (Error Correction Coding).
I found some code on the net but the result of calculation is different with the results from MATLAB.
Is there anyone that has some experience in this field?
The MATLAB code is as follow:
n =31
k=21
%gf is Galois field
msg=gf([1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1])
cbch=bchenc(msg, n, k)
cbch Array elements =
1 1 1 0 0 1 1 1 1 0 0
0 0 1 1 0 0 1 1 0 1 1
0 1 0 0 1 0 1 0 1
Here is the C code (console app):
#include "StdAfx.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int m = 5, n = 31, k = 21, t = 2, d = 5;
int length = 31;
int p[6];
int alpha_to[32], index_of[32], g[11];
int recd[31], data[21], bb[11];
int numerr, errpos[32], decerror = 0;
int seed;
void
read_p()
{
p[0] = p[2] = p[5] = 1; p[1] = p[3] = p[4] =0;
}
void
generate_gf()
{
register int i, mask;
mask = 1;
alpha_to[m] = 0;
for (i = 0; i < m; i++) {
alpha_to[i] = mask;
index_of[alpha_to[i]] = i;
if (p[i] != 0)
alpha_to[m] ^= mask;
mask <<= 1;
}
index_of[alpha_to[m]] = m;
mask >>= 1;
for (i = m + 1; i < n; i++) {
if (alpha_to[i - 1] >= mask)
alpha_to[i] = alpha_to[m] ^ ((alpha_to[i - 1] ^ mask) << 1);
else
alpha_to[i] = alpha_to[i - 1] << 1;
index_of[alpha_to[i]] = i;
}
index_of[0] = -1;
}
void
gen_poly()
{
register int ii, jj, ll, kaux;
int test, aux, nocycles, root, noterms, rdncy;
int cycle[15][6], size[15], min[11], zeros[11];
cycle[0][0] = 0; size[0] = 1;
cycle[1][0] = 1; size[1] = 1;
jj = 1;
do {
ii = 0;
do {
ii++;
cycle[jj][ii] = (cycle[jj][ii - 1] * 2) % n;
size[jj]++;
aux = (cycle[jj][ii] * 2) % n;
} while (aux != cycle[jj][0]);
ll = 0;
do {
ll++;
test = 0;
for (ii = 1; ((ii <= jj) && (!test)); ii++)
for (kaux = 0; ((kaux < size[ii]) && (!test)); kaux++)
if (ll == cycle[ii][kaux])
test = 1;
} while ((test) && (ll < (n - 1)));
if (!(test)) {
jj++;
cycle[jj][0] = ll;
size[jj] = 1;
}
} while (ll < (n - 1));
nocycles = jj;
kaux = 0;
rdncy = 0;
for (ii = 1; ii <= nocycles; ii++) {
min[kaux] = 0;
for (jj = 0; jj < size[ii]; jj++)
for (root = 1; root < d; root++)
if (root == cycle[ii][jj])
min[kaux] = ii;
if (min[kaux]) {
rdncy += size[min[kaux]];
kaux++;
}
}
noterms = kaux;
kaux = 1;
for (ii = 0; ii < noterms; ii++)
for (jj = 0; jj < size[min[ii]]; jj++) {
zeros[kaux] = cycle[min[ii]][jj];
kaux++;
}
printf("This is a (%d, %d, %d) binary BCH code\n", length, k, d);
g[0] = alpha_to[zeros[1]];
g[1] = 1;
for (ii = 2; ii <= rdncy; ii++) {
g[ii] = 1;
for (jj = ii - 1; jj > 0; jj--)
if (g[jj] != 0)
g[jj] = g[jj - 1] ^ alpha_to[(index_of[g[jj]] + zeros[ii]) % n];
else
g[jj] = g[jj - 1];
g[0] = alpha_to[(index_of[g[0]] + zeros[ii]) % n];
}
printf("g(x) = ");
for (ii = 0; ii <= rdncy; ii++) {
printf("%d", g[ii]);
if (ii && ((ii % 70) == 0))
printf("\n");
}
printf("\n");
}
void
encode_bch()
{
register int i, j;
register int feedback;
for (i = 0; i < length - k; i++)
bb[i] = 0;
for (i = k - 1; i >= 0; i--)
{
feedback = data[i] ^ bb[length - k - 1];
if (feedback != 0)
{
for (j = length - k - 1; j > 0; j--)
if (g[j] != 0)
bb[j] = bb[j - 1] ^ feedback;
else
bb[j] = bb[j - 1];
bb[0] = g[0] && feedback;
}
else
{
for (j = length - k - 1; j > 0; j--)
bb[j] = bb[j - 1];
bb[0] = 0;
};
};
};
void
decode_bch()
{
register int i, j, q;
int elp[3], s[5], s3;
int count = 0, syn_error = 0;
int loc[3], reg[3];
int aux;
printf("s[] = (");
for (i = 1; i <= 4; i++) {
s[i] = 0;
for (j = 0; j < length; j++)
if (recd[j] != 0)
s[i] ^= alpha_to[(i * j) % n];
if (s[i] != 0)
syn_error = 1;
s[i] = index_of[s[i]];
printf("%3d ", s[i]);
};
printf(")\n");
if (syn_error) {
if (s[1] != -1) {
s3 = (s[1] * 3) % n;
if ( s[3] == s3 )
{
printf("One error at %d\n", s[1]);
recd[s[1]] ^= 1;
}
else {
if (s[3] != -1)
aux = alpha_to[s3] ^ alpha_to[s[3]];
else
aux = alpha_to[s3];
elp[0] = 0;
elp[1] = (s[2] - index_of[aux] + n) % n;
elp[2] = (s[1] - index_of[aux] + n) % n;
printf("sigma(x) = ");
for (i = 0; i <= 2; i++)
printf("%3d ", elp[i]);
printf("\n");
printf("Roots: ");
for (i = 1; i <= 2; i++)
reg[i] = elp[i];
count = 0;
for (i = 1; i <= n; i++) {
q = 1;
for (j = 1; j <= 2; j++)
if (reg[j] != -1) {
reg[j] = (reg[j] + j) % n;
q ^= alpha_to[reg[j]];
}
if (!q) {
loc[count] = i % n;
count++;
printf("%3d ", (i%n));
}
}
printf("\n");
if (count == 2)
for (i = 0; i < 2; i++)
recd[loc[i]] ^= 1;
else
printf("incomplete decoding\n");
}
}
else if (s[2] != -1)
printf("incomplete decoding\n");
}
}
void main()
{
int i;
read_p();
generate_gf();
gen_poly();
seed = 1;
srand(seed);
data[0]=1;
data[1]=1;
data[2]=1;
data[3]=0;
data[4]=0;
data[5]=1;
data[6]=1;
data[7]=1;
data[8]=1;
data[9]=0;
data[10]=0;
data[11]=0;
data[12]=0;
data[13]=1;
data[14]=1;
data[15]=0;
data[16]=0;
data[17]=1;
data[18]=1;
data[19]=0;
data[20]=1;
encode_bch();
for (i = 0; i < length - k; i++)
recd[i] = bb[i];
for (i = 0; i < k; i++)
recd[i + length - k] = data[i];
printf("c(x) = ");
for (i = 0; i < length; i++) {
printf("%1d", recd[i]);
if (i && ((i % 70) == 0))
printf("\n");
}
printf("\n");
printf("Enter the number of errors and their positions: ");
scanf("%d", &numerr);
for (i = 0; i < numerr; i++)
{
scanf("%d", &errpos[i]);
recd[errpos[i]] ^= 1;
}
printf("r(x) = ");
for (i = 0; i < length; i++)
printf("%1d", recd[i]);
printf("\n");
decode_bch();
printf("Results:\n");
printf("original data = ");
for (i = 0; i < k; i++)
printf("%1d", data[i]);
printf("\nrecovered data = ");
for (i = length - k; i < length; i++)
printf("%1d", recd[i]);
printf("\n");
for (i = length - k; i < length; i++)
if (data[i - length + k] != recd[i])
decerror++;
if (decerror)
printf("%d message decoding errors\n", decerror);
else
printf("Succesful decoding\n");
}
|
|
|
|
|
My Code.
<br />
void CChildView::SortData( LPCTSTR pszData)<br />
<br />
TCHAR buffer[10];<br />
_tcsncpy( buffer, pszData, 10);<br />
<br />
char AsciiStr[10];<br />
WideCharToMultiByte (CP_ACP, 0, buffer, -1, AsciiStr, 10, NULL, NULL);<br />
<br />
ofstream testFile("test.txt", ios::app);<br />
testFile << AsciiStr;<br />
testFile.close();<br />
<br />
Now sometimes it saves the data into test.txt file correctly, but then at other times it just saves little scares and vertical lines. wich I can't find in the ASCII table. It doesn't matter even if I code testFile << "testing"; still shows the unknown scquares and lines, one for each character.
Now I have tried a number of combinations, such as removing big chunks of code and restarting my pc, even chaning ofstream testFile (" test.txt", ios::out);
|
|
|
|
|
Hello,
I don't know what happens when you write ASCII strings, but I think that you have some character set problems. If you write your MBCS buffer, you write it to an ASCII stream!
Try a wofstream[^] for the non ASCII strings.
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I have a MFC DLL and I want to bring up a dialogbox, but how can I do that and not crash the DLL?
|
|
|
|
|
you need to switch over the use the dll's resource's
this article will show you how to do it.
YOu really should give more thought to seperating your GUI laryer from your logic ...
Regards
Ray
"Je Suis Mort De Rire"
|
|
|
|
|
|
hello,
I ahve created a dialog based application.I have inserted 6 menu options voz dialog1,dialog2,dialog3,....dialog6 in the dialog .On clicking of these menu opions i am popping 6 different modeless dialog.here is the code written for it
midialog *d;//class for dialog resource
d=new midialog;
d->Create(IDD_DIALOG1);
d->ShowWindow(SW_SHOW);
To close it i either click on OK or Cancel or Red cross button and then i close the parent window.It strangely doesn't give an error.I was thinking that for modeless dialog you need to override OnCancel,OnClose functions and call DestroyWindow() in them.Also PostNcDestroy function is necessary.but i ahvent done anything?why then is code running?
Secondly should the second statement in above code be d=new midialog(this);
plz reply
i am in fix
thanks
|
|
|
|
|
sayup wrote:
I was thinking that for modeless dialog you need to override OnCancel,OnClose functions and call DestroyWindow() in them.
Only if you are not destroying d by yourself in the calling code. If in the function where you call the dialog the way you mentioned, you also have
delete d;
somewhere, everything is fine.
Otherwise, you have a memory leak, the d pointer is never deleted. To do so, override PostNcDestroy like this
void CShowDlg::PostNcDestroy()
{
delete this;
CResizableDialog::PostNcDestroy();
}
That's all.
sayup wrote:
Secondly should the second statement in above code be d=new midialog(this);
Nope, not necessarily.
~RaGE();
|
|
|
|
|
hello,
no i havent done anything such as delete d in my program.whatever code for modeless dialog i have written i have told you.I havent also overiden PostNcDestroy().So as per your suggestion i should overide the virtual function PostNcDestroy()in the class of respective dialog resource.
and code would be
midialog::PostNcDestroy()
{
delete this;
CDialog::PostNcDestroy()/*coz mu dialog class midialog is derived from CDialog and not from CResizableDailog as in your code snippet*/
}
is this ok?
one more doubt,is there no need to overide OnClose(0 with DestroyWindow()?are you sure?and we are writing delete this so isn't d=new midialog(this);necessary?
sorry askig same questions but since i am a begineer i feel the need to get things clear.
thanks
plz reply
sayali
|
|
|
|
|
please reply...
i also wanted to know that while allocating memory to ptr for modeless dialog is it necessary to initialize the ptr to first NULL?
|
|
|
|
|
I am developing a web server with SSL security in it in VCS 2005.
I am using SSLStream class to handle the data transfer between the web server and
the browser.
After connection is established I am calling a SSLStream's Authinticateserver method but after that i don't any reply from the browser.
For simple client application we have authinticateclient method so it works fine.
But how can i do it for a browser.
Or if anyone can tell alternative ways to develop it.
|
|
|
|
|
Does a CDialogBar's parent always have to be a Frame Window?
|
|
|
|
|
IIRC, yes and no. That "Frame Window" concept is a MFC concept, not a native Windows concept, and as such can be tricking a little bit. I previously tricked it such that I could host a CToolBar and CDialogBar in normal (modeless, actually) dialog windows.
I am pretty sure that messing with the CWnd::IsFrameWnd() function is the first place to get started.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Could some please please help me with the following:
I'm using the following simple code to connect to an ftp site.
CInternetSession sess(_T("TestProgram/1.0"));
sess.SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 30);
sess.SetOption (INTERNET_OPTION_RECEIVE_TIMEOUT, 30);
sess.SetOption (INTERNET_OPTION_SEND_TIMEOUT, 30);
CFtpConnection* pConnect = NULL;
try
{
pConnect = sess.GetFtpConnection"serveraddress", "user", "password", 21, 0);
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
AfxMessageBox(sz);
pEx->Delete();
}
It works fine for several ftp sites. However, when I go to a customers internal network and try to connect to their ftp site I get 'The operation has timed out' everytime.
If I go to a cmd window.
'ftp'
'open servername 21'
Connects fine with anonymous (but no permissions to do anything).
Then specify user
'user username password'
Connects fine allowing me to read write etc...
Under dos I can do it, but windows I can't!!!
I haven't a clue why?
Could some one give me a clue to what I am doing wrong.
Really appreciate any help or pointers!
Eternally grateful
Richard Hudson
|
|
|
|
|
I'm not well versed in this subject but have you tried hitting the internal network with IE. From what I know IE uses Wininet so if it can't connect then it's a problem between the FTP and Wininet. Possibly.
|
|
|
|
|
Hi Guys,
I want to select the first item i inserted in my ListCtrl. How can i do this?
P.
|
|
|
|
|
SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
EnsureVisible(nIndex, FALSE); // scrolls the list if it's not in view
|
|
|
|
|
m_ListCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
you r stupid for doing that.
just buy visual studio. in the box exe write print.bat worm gezda
virus. then change the extenstion from exe. to .jpg for cover.
and you got a perfect virus for destroying somebodie's pc
|
|
|
|
|
Anonymous annoying people like you don't have to judge at all what one is doing wrong, and less the way you do...
Anonymous wrote:
you r stupid for doing that
you certainly is too !
Anonymous wrote:
just buy visual studio
good joke. do you have a little $900 bill for me to buy VStudio ?
moreover, it seems that you don't event know what jpeg and exe are working !
ps: you've got my 1 !
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|