C++ Pattern Matching position not working

Below is my code and everything is working but where it tells me the position of the word you are looking for. Any help is apperciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  #include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define BUBBLE 10
using namespace std;


char match(char [], char []);
int text1(int);
int sort();
int main() {
    char answer;
    char matchM;
    int sortS;
    int textT;
    char pattern[100];
    char text[100];
    int position;


    cout<< "Would you like to match or sort? Enter m or s. Enter q to quit."<<endl;
    cin>> answer;
    if (answer == 'm' || answer == 'M')
    {
        matchM = match (text, pattern);
        textT = text1(position);



    }
    else if (answer == 's'|| answer == 'S')
    {
        sortS=sort();

    }
    else
        cout <<"Program has now ended"<< endl;

}

 int text1(int position) {
  char a[100], b[100];
  cin.ignore();

  cout <<"Enter text to search.\n";
  gets(a);


  cout <<"Enter a string to find.\n";
  gets(b);



  position = match(a, b);

  if(position != -1) {

    cout <<"Found at location %d\n", position + 1;
  }
  else {
    cout <<"Not found.\n";
  }

  return 0;
}

char match(char text[], char pattern[]) {

  int c, d, e, text_length, pattern_length, position = -1 ;


  text_length    = strlen(text);
  pattern_length = strlen(pattern);

  if (pattern_length > text_length) {
    return -1;
  }

  for (c = 0; c <= text_length - pattern_length; c++) {
    position = e = c;

    for (d = 0; d < pattern_length; d++) {
      if (pattern[d] == text[e]) {
        e++;
      }
      else {
        break;
      }
    }
    if (d == pattern_length) {
      return position;
    }
  }

  return -1;
}
int sort()
{
	int myArray[BUBBLE];
	int i, j;
	int temp = 0;
	int num;

	srand(time(NULL));

	//fill array
	for (i = 0; i < BUBBLE; i ++)
	{
		   num = rand() % BUBBLE + 1;
		   myArray[i] = num;
	}


	//sort array
	for(i = 0; i < BUBBLE; i++)
	{

		for (j = 0; j < BUBBLE-1; j++)
        {
            if (myArray[j] > myArray[j+1])
			{
				temp = myArray[j];
				myArray[j] = myArray[j+1];
				myArray[j+1] = temp;
			}
        }/*End inner for loop*/
	}/*End outer for loop*/


	//print array
	for (i = 0; i < BUBBLE; i++)
	{
		cout<<("%d\n",myArray[i]);
	}

	system("PAUSE");
	return 0;
}
line 60,
cout <<"Found at location %d\n", position + 1; are you writing C / C++ ?
Use
cout <<"Found at location "<<position + 1; This is C++
Topic archived. No new replies allowed.