|
Thanks! I will try some of them
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi-
Did you try just using the RegEx class from boost ?
There are no templates to deal with and it performs like a champ.
Example without templates.
#include <cstdlib>
#include "boost/cregex.hpp"
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
int main (int ac, char ** av)
{
RegEx rgx;
rgx = "pu.[a-f].c";
static char * matchStrings[] = {
"dpublic",
"pablic",
"private",
"chennai",
"whatsthis",
"pjslic",
"puslic",
"this string wont public",
NULL
};
for (char ** p = matchStrings; *p!=NULL; p++)
{
char * p2 = *p;
if(rgx.Match(p2))
{
printf("String %s \t*MATCH FOUND*\n",p2);
}
else
{
printf("String %s \tNo Match\n",p2);
}
}
return 0;
}
|
|
|
|
|
Yes I did. That's some code I'm using right now, and it preforms very well:
char *param_re = "^(.+)"(.+)"(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2}),(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2}),(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2})"(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2}),(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2}),(2[0-5][0-5]|1[0-9][0-9]|[0-9]{1,2})"([0-9]+),([0-9]+),([0-9]+),([0-9]+)"([0-9]+),([0-9]+),([0-9]+),([0-9])+"([0-9]+),([0-9]+)("debug)?$";
regex expr(param_re);
cmatch matches;
if(!regex_match(data, matches, expr))
return;
But what I find somehow complicated is to assign the values inside the parentheses to chars:
std::string value;
value.assign(matches[i].first, matches[i].second);
Maybe that's just so strange to me, because I have nearly no knowledge of STL and string .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Simple program embedded in an Active X Control. All Mouse Events get executed, but keyboard events are not getting called. Is there any configuration or directive I need to do to enable all the keyboard events to be called within my code?
Thanks in advance!!!
// Key.cpp : Implementation of CKey
#include "stdafx.h"
#include "KeyDemo.h"
#include "Key.h"
/////////////////////////////////////////////////////////////////////////////
// CKey
LRESULT CKey::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) // Currently this method never gets called.
{
MessageBox("On Key Down");
return 0;
}
LRESULT CKey::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
MessageBox("LButtonDown");
return 0;
}
Appreciate your help on this.
|
|
|
|
|
In addition to this I can only use Win32 API. MFC cannot be used.
|
|
|
|
|
Hello, C++ Newbie here. I have been trying to compile this program for two days and cannot seem to get it right.
I wrote a program that acts like a bank deposit. It will ask for the account number, annual rate, years of loan, and the principal balance. The program asks for all of this information, sends the variables to a function "compute", and then prints the annual interest earned back in main:
#define n 5
struct deposit {
char acnumber[10];
float* rate;
float* principal;
int* years;
float amount; };
float compute(float*,float*,int*);
void main() {
deposit d[n];
cout<<"Please enter the account information."<<endl;
for(int="" i="0;i<n;i++)" {
="" cout<<"enter="" the="" 9="" digit="" account="" number:="" ";
="" cin="">>d[i].acnumber;
cout<<"Enter number of years: ";
cin>>d[i].years;
cout<<"Enter the rate: ";
cin>>d[i].rate;
cout<<"Enter the principal amount: ";
cin>>d[i].principal;
}
compute((*d).rate,(*d).principal,(*d).years);
cout<<"The amount is: "<< d.amount <
|
|
|
|
|
webblynx wrote:
for(int i=0;i cout<<"Enter the 9 digit account number: ";
for(int i=0;i d[i].amount=(d[i].rate/100) * (d[i].principal) * (d[i].years);
What's up with these lines? Surely your compiler complained about them not being syntactically incorrect.
webblynx wrote:
compute((*d).rate,(*d).principal,(*d).years);
Instead of passing a mess of pointers to the compute() function, just pass the address of the local variable d, like:
compute(&d);
And change the function to be:
float compute(deposit *pDeposit)
|
|
|
|
|
DavidCrow wrote:
for(int i=0;i cout<<"Enter the 9 digit account number: ";
for(int i=0;i d[i].amount=(d[i].rate/100) * (d[i].principal) * (d[i].years);
I did this so that I could define the number of accounts to add at the beginning of the program. I tried to make a dynamic version of this but was unsucessful.
DavidCrow wrote:
compute(&d);
I changed the function call to this, but now I am getting:
"error C2664: 'compute' : cannot convert parameter 1 from 'struct deposit (*)[5]' to 'struct deposit' No constructor could take the source type, or constructor overload resolution was ambiguous"
C++ Newbian
|
|
|
|
|
Here's one possible solution:
struct deposit <br />
{<br />
char acnumber[10];<br />
double rate;<br />
double principal;<br />
int years;<br />
double amount; <br />
};<br />
<br />
double compute( deposit *pDeposit ) <br />
{<br />
pDeposit->amount = (pDeposit->rate / 100.0) * pDeposit->principal * (double) pDeposit->years;<br />
<br />
return pDeposit->amount;<br />
}<br />
<br />
void main() <br />
{<br />
deposit d[n];<br />
<br />
cout << "Please enter the account information." << endl;<br />
<br />
for (int i = 0;i < n; i++)<br />
{<br />
cout << "Enter the 9 digit account number: ";<br />
cin >> d[i].acnumber;<br />
<br />
cout << "Enter number of years: ";<br />
cin >> d[i].years;<br />
<br />
cout << "Enter the rate: ";<br />
cin >> d[i].rate;<br />
<br />
cout << "Enter the principal amount: ";<br />
cin >> d[i].principal;<br />
<br />
cout<<"The amount is: " << compute(d) << endl;<br />
}<br />
}
Here's another:
struct deposit <br />
{<br />
char acnumber[10];<br />
double rate;<br />
double principal;<br />
int years;<br />
double amount; <br />
};<br />
<br />
void compute( deposit *pDeposit ) <br />
{<br />
for (int i = 0;i < n; i++)<br />
pDeposit[i].amount = (pDeposit[i].rate / 100.0) * pDeposit[i].principal * (double) pDeposit[i].years;<br />
}<br />
<br />
void main() <br />
{<br />
deposit d[n];<br />
<br />
cout << "Please enter the account information." << endl;<br />
<br />
for (int i = 0;i < n; i++)<br />
{<br />
cout << "Enter the 9 digit account number: ";<br />
cin >> d[i].acnumber;<br />
<br />
cout << "Enter number of years: ";<br />
cin >> d[i].years;<br />
<br />
cout << "Enter the rate: ";<br />
cin >> d[i].rate;<br />
<br />
cout << "Enter the principal amount: ";<br />
cin >> d[i].principal;<br />
}<br />
<br />
compute(d);<br />
}
The [code][/code] tags kill the indentation. Sorry!
|
|
|
|
|
I just came up with something very similiar except that I had the function at the end.
Good job!
Thanks very much!
C++ Newbian
|
|
|
|
|
Hi there,
Can anyone please provide some insight to the below problem?
I am calling:
const hostent* HostInfo =
::gethostbyaddr((const char*)(&binaryIp), sizeof(binaryIp), AF_INET);
binary ip is the correct local ip of a machine on our network. Instead of returning the machine's name, HostInfo->h_name takes on the "xxx.com" name of our company! Any ideas why this is happening?
Thanks!
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
Look at HostInfo->h_addr_list instead.
|
|
|
|
|
Thanks but this doesn't work....
HostInfo->h_name is "simrad.com"
HostInfo->h_addr_list[0] is "xxxsimrad.com", where xxx are some funny accented characters...
Any other thoughts?
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
Are you looking at HostInfo->h_addr_list[0] in its "raw" format or are you converting it with inet_ntoa()?
in_addr **ip = (in_addr **) HostInfo->h_addr_list;<br />
TRACE("%s\n", inet_ntoa(**ip));
|
|
|
|
|
The code you gave me TRACE()s out the correct ip address. Unfortunately this is no help, because I already know the ip address. I need to determine the host name from the ip address, which should be a string.
Any other thoughts?
Thanks,
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
My bad. I got this thread confused with another one. I'm not a network technician so I don't know what all needs to be in place for DNS translation and NAT to work.
Does this help:
char **p = HostInfo->h_aliases;
TRACE("%s\n", *p);
|
|
|
|
|
No it doesn't... I have looked through the whole HostInfo structure in the debugger, with no luck. Thanks anyways though...
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
Try this.. it works for me.
struct hostent *hp;
unsigned int addr;
addr = inet_addr("192.168.1.100");
hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
MessageBox(hp->h_name);
Hope this helps,
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Check your company dns for proper reverse lookup records first.
try nslooup
>set type=PTR
>123.12.12.12
Many places don't bother with PTRs.
Brian
|
|
|
|
|
I don't follow... am I supposed to type that into the command prompt or something?
Thanks.
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
Test your dns server reverse lookups. If your dns server set to return junk, junk is what you will get.
nslookup shows dns responses.
|
|
|
|
|
hello
i am making a simple program in c++ and am using a simple class of my
own called item.
i have created a pointer to this node as follows:
pnode = new node;
and then i check if it has been created properly:
if (pnode)
...
the problem is that checking if it has been created doesnt work -
if i get rid of the defining line, the program still thinks pnode is
a valid object, even though if i debug the program the value of pnode
is "0xcccccccc" which i think means null.
i have tried using if (pnode == null) and other things but i cant get
this simple check to work.
this is only a simple 16 line program with a simple winmain function, so
can anybody tell me what im doing wrong?
thank you
|
|
|
|
|
sorry, the class is named node, not item.
|
|
|
|
|
Berkut wrote:
the value of pnode is "0xcccccccc" which i think means null.
No, a NULL pointer has a value of 0. The /GZ compiler option sets uninitialized variables to 0xCCCCCCCC.
Does the node class have a default constructor? Unless you've done something to it, the new operator calls a class's default constructor.
Berkut wrote:
i have tried using if (pnode == null)
This should actually be if (pnode == NULL), or better still if (NULL == pnode)
|
|
|
|
|
DavidCrow wrote:
This should actually be if (pnode == NULL), or better still if (NULL == pnode)
Interesting. Is there an explanation for that?
// Afterall I realized that even my comment lines have bugs
|
|
|
|