#include <iostream>
using std::cout;
using std::endl;
#include <cstring>
using std::strcpy;
using std::strcat;
#include <cstdio>
using std::sprintf;
int main()
{
char * lb = "(?:[a-z90](?:-?[a-z90]+)+)";
int lbLen = strlen(lb);
char * sbFrmat = "(?:%s(?:\\.%s){0,4})";
int sbFrmatLen = strlen(sbFrmat);
int sbLen = (lbLen * 2) + sbFrmatLen;
char sb[sbLen+1];
sprintf(sb, sbFrmat, lb, lb);
cout << "sb\n" << sb << endl << endl;
char * i_num = "(15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])";
int iNumLen = strlen(i_num);
char * iFrmat = "(%s(?:\\\\.%s){3})";
int iFrmatLen = strlen(iFrmat);
int iLen = (iNumLen * 2) + iFrmatLen;
char i[iNumLen + 1];
sprintf(i, iFrmat, i_num, i_num);
cout << "i\n" << i << endl << endl;
char * dmFrmat = "(?:%s)";
int dmFrmatLen = strlen(dmFrmat);
int dmLen = lbLen + dmFrmatLen;
char dm[dmLen + 1];
sprintf(dm, dmFrmat, lb);
cout << "dm\n" << dm << endl << endl;
char tp_l[] = "([abcd]{2,4})";
int tpLLen = strlen(tp_l);
char p_num[] = "(0-9]+)";
int pNumLen = strlen(p_num);
char * hFrmat = "((?:(?:%s\\.)?%s\\.%s|%s)(?:\\:%s)?)";
int hFrmatLen = strlen(hFrmat);
int hLen = sbLen + dmLen + tpLLen + iLen + pNumLen+ hFrmatLen;
char h[hLen + 1];
sprintf(h, hFrmat,
sb,
dm,
tp_l,
i,
p_num);
cout << "h\n" << h << endl;
}
//output
sb
(?:(?:[a-z90](?:-?[a-z90]+)+)(?:\.(?:[a-z90](?:-?[a-z90]+)+)){0,4})
i
((15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])(?:\\.(15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])){3})
dm
(?:(?:[a-z90](?:-?[a-z90]+)+))
h
((?:(?:5[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])){3})\.)?(?:(?:[a-z90](?:-?[a-z90]+)+))\.([abcd]{2,4})|((15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])(?:\\.(15[1-4]|1[1-4][1-9]|[0-1]?[0-9]?[0-9])){3}))(?:\:(0-9]+))?)
In the sprintf that fills "h" notice that "sb" is the first argument for formatting but sb's value "(?:(?:[a-z90)) ..." comes later on in the "h" string and the "i" value is shown twice. At the beginning of "h" the i value shows up but not completely accurate.
I'm building a regular expression, and don't understand what's going wrong.
Btw, the regexes above aren't exactly what I'm using but close enough to illustrate the point.
Also, If someone could give a brief example of how I could accomplish the concatenation that I'm doing above with C++ I'd appreciate it. I'd first like to know what's going wrong with my sprintf's though.
I've looked at "stringstream" but had problems with the stream object (if that's what you'd call it). Where it would keep the contents of the previously streamed input (stream << etc. Again not certain of the terminology) and I didn't know how to have it simply reset itself.
Thanks in advance for any information you're able to give.