0

I need help with my problem. I have an array of strings which is string * A.

A = { dog, doom, dorm, dunk, face, fall, falafel, fart }

I need to check how many string "d" in the array which is 4.
I need to check how many string "do" in the array which is 3.

I was to use binary search to find it. My problem is how do I access part of the string in the array and be able to compare it with another string?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • You give pseudo code and ask for real code -- how can we know? – Chad Apr 15 '17 at 02:22
  • "I was to use binary search to find it" - how did you "access" the strings in your array when you did *that*? Chances are it will be a similar endeavor. – WhozCraig Apr 15 '17 at 02:22
  • [check-if-a-string-contains-a-string](https://stackoverflow.com/questions/2340281/check-if-a-string-contains-a-string-in-c) – HDJEMAI Apr 15 '17 at 02:24
  • Possible duplicate of [Check if a string contains a string in C++](http://stackoverflow.com/questions/2340281/check-if-a-string-contains-a-string-in-c) – YiFei Apr 15 '17 at 05:37

1 Answers1

0

The string data type in c++ is, in other words, a char array (char[]), for example:

#include <conio.h>
#include <string>
#include <iostream>

using namespace std;


int main() {
    //Declare the array
    string foo[3];

    //Inserting values in the strings
    foo[0] = "First word";
    foo[1] = "Second word";
    foo[2] = "Third word";

    //Show the first word of the first string
    cout << foo[0][0];

    _getch();

    return 0;
}

So you can compare each character with that.

Raven H.
  • 72
  • 10