?
Solved

c code for searching pascal-style strings

Posted on 1998-06-30
1
Medium Priority
?
195 Views
Last Modified: 2013-12-26
I have a dialog text-edit box that the user will type in what he wants to search for. Then I need to search through about 100 STR# for any matches. I can retrieve the text for the text-edit box, but then I don't really know where to go. All the c functions for handeling strings expect a c-style string, so it'd be a pain to covert everything. I heard something about a PStrCmp function, but I can't get it to work. Does anyone have some code or nifty functions that can help me? Thanks!
0
Comment
Question by:anthonyz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
roov earned 150 total points
ID: 1291487
First, don't give so easily on conversion.
You might want to keep all your string resources in memory anyway, since loading them from the resource takes time, and if you keep them in memory, you might as well keep them as C strings, then get your user's string, convert it to C style, then use strstr or something similar.

Additionaly, the Mac Toolbox has EqualString, which compares two Pascal style strings.
The brute force of doing this search might look similar to this (without error checking/recovery):
short FindPattern(StringPtr inPattern, StringPtr inData)
{
      // return index of inPattern. ) if not found. Find last occurance...
      short location = 0;
      if (inData[0] < inPattern[0])
            return 0;
      if ((inData[0] == inPattern[0]) &&
            (EqualString(inData, inPattern, true, false))
      {
            return 1;
      }
      for (short ind = inData[0] - inPattern[0]; ind > inPattern[0]; ind--) {
            unsigned char storage = inData[ind];
            Boolean foundPattern = false;
            inData[ind] = inPattern[0];
            foundPattern = EqualString(&(inData[ind]), inPattern, true, false);
            inData[ind] = storage;
            if (foundPattern) {
                  location = ind;
                  break;
            }
      }
      return location
}

Sorry if this has minor bugs...

Enjoy...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question