Error and Bubble Sort Problem

This is my code below and I cannot figure out two things one is that I keep getting an error that says "cannot convert 'int (*)()' to 'char*' for argument '1' to 'int match(char*, char*)' The error is in line 25. The second is the bubble sort portion is not printing out in a sorted form and I don't know why. Any help is appreciated.





#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define BUBBLE 10
using namespace std;


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

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

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

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

}

int text() {
char a[100], b[100];
int position;

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

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

position = match(a, b);

if(position != -1) {
printf("Found at location %d\n", position + 1);
}
else {
printf("Not found.\n");
}

return 0;
}

int 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;
}
Last edited on
int match(char [], char []);
matchM= match (text (textT?), pattern);
char matchM;
char pattern;
int textT;

You define that match function takes two character arrays as parameters and returns an integer. But matchM is a char type variable, not an integer, and neither textT nor pattern are defined as character arrays.
Topic archived. No new replies allowed.