EDIT:
Once again, I ll try to explain it more precisely.
Am writing IRC client - network application based on sockets. Receiving data from server with recv()
function and storing them in the rBuf[]
array one character after another.
Then copying them to array rBufh[]
which is passed to parsing function.
Important thing is that server is sending just one character at a time [one char in one recv()] and keys (char arrays stored in two dim. array [key1
]) are the strings which if parsing method finds one of them in received data it needs to react properly basing it reaction on the 3 digits code which meaning is specified in protocol documentation. - as for basics.
Parsing algorithm/function works as follows:
key1
(containing keys) andrBufh
arrays are the arguments passed to it- Take first char of the first string stored in
key1
and compare it with first char ofrBufh
- If they match return
int ret = 2
(which means 'part of key has been found in received data'
Now recv()
adds one char (as the server only sends on char each time) to rBufh
array which is passed to parsing function once again and the algorithm starts again till it finds matching key, returning int ret = 1
(found matching key) or int ret = 0
if in step 3 they did not match.
While parser is working, printing to stdout is stoped and basing on value returned by parser printing is either stoped for a longer time (if part of one of the keys from key1
array is found) or allowed to print (if whole key has been found or parser can't match letter passed to it in rBufH
array to any of keys stored in key1
)
We are getting closer to understanding what I asked for - I hope : )
Quantity of strings stored in key1
array is known beforehand as they are specified in the protocol doc. so initializing it is possible right away while defining.
What i asked is:
is it possible to pass to key1
(not necessarily using sprintf as I did - it just seemed convenient) string which will contain some part of code meaning 'any three digits'.
e.g.
lets mark by XXX the part of code mentioned 3 lines above
key1[0] = "irc2.gbatemp.net XXX nickname"
and now if parser come across any string matching key1[0] which contains ANY three digits in place of XXX it will return 1 - so other function will have posibility to react properly.
This way i don't have to store many strings with different values of XXX in key1
array but just one which maches all of them.
Ok, now I really did my best to help You understand it and so gain an answer : )
Greetings
Tom
P.S.
Feel free to change the title of this topic as I don't really know how should i discribe the problem in few words as You already noticed. (it is as it is because my first idea was to pass some regex to key1
)