error coming-error: invalid conversion from 'char*' to 'char' [-fpermissive]
cout<< par(s,n1,num1,word);
Why calling par()
function in main causing invalid conversion from char* to char?
Tried a lot to find the reason myself. I am a beginner in c++. I don't find anything wrong in the par() function. I haven't done assignment mismatch anywhere in the function, well thinking that there may be an error due to arguments presented in function par()
#include<iostream>
#include<string.h>
using namespace std;
int par(char s[][80],int,int,char);
char* substr(char*,int,int);
int main()
{
char s[][80]={{"this is rockstar"},{"I am rockstar"},{"the best one"},{"no one can dare"},{"rockstar rocks always"}};
char word[80]={"rockstar"};
int n1=5;
int num1=0;
cout<<par(s,n1,num1,word);
return 0;
}
int par(char s[][80],int n1,int num1,char word[80])
{
int k=0;
int length_word=strlen(word);
int t=0;
char beg[80];
while(t!=strlen(word))
{
beg[t]=word[t];
t++;
}
beg[t]=" ";
char end[80];
char mid[80];
mid[0]=' ';
t=0;
int l=1;
while(t!=strlen(word))
{
mid[l]=word[t];
l++;
t++;
}
mid[l]=' ';
t=0;
l=1;
end[0]=' ';
while(t!=strlen(word))
{
end[l]=word[t];
t++;
l++;
}
char temp[80];
while(k<n1-1)
{
int i=0;
while(s[k][i]!='\0')
{
temp[i]=s[k][i];
i++;
}
if(strcmp(substr(temp,1,strlen(word)+1),beg)==0)
{
num1+=1;
}
int tr;
for(tr=2;tr<strlen(temp)-(strlen(word)+2);tr++)
{
if(strcmp(substr(temp,j,strlen(word)+2),mid)==0)
{
num1+=1;
}
}
if(strcmp(substr(temp,strlen(temp)-strlen(word),strlen(word)+1),end)==0)
{
num1+=1;
}
k++;
}
return num1;
}
char* substr(char *s,int i, int j)
{
int pos=i-1;
static char res[80];
int k=0;
while(pos<=i+j-2)
{
res[k]=s[pos];
pos++;
k++;
}
return res;
}