HWZ Forums

Login Register FAQ Mark Forums Read

need help on c

LinkBack Thread Tools
Old 09-07-2010, 08:21 AM   #16
Supremacy Member
fzhfzh's Avatar
Join Date: May 2008
Posts: 8,619
If you use strstr, you need string.h, which is a C++ library and no longer C.

You can just read the whole text into an char array, and replace the strstr function with this function:
bool function bCheckString (char* cInput, char* cSearch, int iInputMax, int iSearchMax)
for(int i = 0; i < (iInputMax-iSearchMax); ++i)
for(int j = 0; (j < iSearchMax) && (cInput[i+j] == cSearch[j]); ++j)
if (j>=iSearchMax) return true;
return false;
replace the return of bool to int if you want to account for number of times the string occurs.
fzhfzh is offline   Reply With Quote
Old 09-07-2010, 08:53 AM   #17
zeroxmxi's Avatar
Join Date: Mar 2007
Posts: 239
If you use strstr, you need string.h, which is a C++ library and no longer C.
I'm afraid you may be misinformed, that string.h is part of the C standard libraries. Here's a non-authoritative source on this subject.


I did remember using it as part of C programming.

While in C++, it was included and wrapped in some directive to be used with the language.

For instance,

#include <iostream>
#include <string>

using namespace std;

int main()
string myString = "Cool";
cout << myString << endl;

zeroxmxi is offline   Reply With Quote
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Terms of Service for more information.

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On