- Joined
- Oct 23, 2007
- Messages
- 1,904
- Points
- 0
Anyone here any good at C++? I need a little help.
Im no so good with C++...
Im no so good with C++...
int __stdcall MyRecv(SOCKET x,char* b,int l,int pr,FARPROC pp)
{
// call original recv
// do content processing here
//replace all instances of the word "hello" with "hi" in the variable "b"
//end processing
typedef int (__stdcall *pS)(SOCKET,char*,int,int);
pS pps = (pS)pp;
int rV = pps(x,b,l,pr);
return rV;
#endif
}
I have a C/C++ programming book made by Deitel, I started reading it when I was in 9th grade, but I had to stop reading it because things (homeworks) got much worse, I read up to page 200 or something like that.NairB said:Incidently, has anyone bought or read Deitel's new C++ book?.....(it also covers game programming with the OGRE graphics library)
spyrorocks said:I dought he gives personal help to people...
#include <iostream>
#include <string>
/* If 'from' matches 'to' or 'from' is empty, */
/* does not parse 's', returns std::string::npos */
/* */
/* Otherwise returns number of replacements done */
/* */
std::string::size_type repl(std::string& s,
const std::string& from,
const std::string& to)
{
std::string::size_type cnt(std::string::npos);
if(from != to && !from.empty())
{
std::string::size_type pos1(0);
std::string::size_type pos2(0);
const std::string::size_type from_len(from.size());
const std::string::size_type to_len(to.size());
cnt = 0;
while((pos1 = s.find(from, pos2)) != std::string::npos)
{
s.replace(pos1, from_len, to);
pos2 = pos1 + to_len;
++cnt;
}
}
return cnt;
}
int main()
{
//std::string s("hellohello my name is hello ok helloshould be hello");
std::string s="hello my name is hello testhellotest";
const std::string old_seq("hello");
const std::string new_seq("hi");
std::cout << "Original string:\n"
<< '"' << s << '"'
<< "\n\n";
const std::string::size_type count(repl(s, old_seq, new_seq));
const std::string dq(count > 0, '"');
const bool parsed(count != std::string::npos);
const bool found(parsed && count > 0);
if(parsed)
{
std::cout << count
<< " occurences of sequence \"" << old_seq << "\""
<< (count ? " replaced with sequence " : " found")
<< dq << (count ? new_seq : "") << dq
<< "\n\n";
}
else
std::cout << "Nothing to change\n\n";
std::cout << (parsed && found
? std::string("New string:\n" + dq + s + dq)
: "No changes made")
<< '\n';
system("pause");
return 0;
}
// recv.h
#include <string>
int __stdcall MyRecv(SOCKET x,char* b,int l,int pr,FARPROC pp)
{
// call original recv
//MessageBox(NULL, b, "data", MB_OK);
//repstring = std::string
std::string temp = b;
int index = temp.find("hello");
while(index != std::string::npos)
{
temp.replace(index, 5, "hi", 2);
index = temp.find("hello");
}
char *copy = new char[temp.size() + 1];
temp.copy(copy, temp.size());
typedef int (__stdcall *pS)(SOCKET,char*,int,int);
pS pps = (pS)pp;
int rV = pps(x,copy,l,pr);
delete [] copy;
return rV;
}