write a function begins(string1, string2) that reurns true if string1 begins string2. Write a program to test the function. program:
#include<stdio.h>
#include<string.h>
char begins(char sentence1[],char sentence2[])
{
int i,j=0;
for(i=0;sentence1!='\0';++i)
{
if(sentence1==sentence2)
j=j+1;
else
if(j==i)
printf("True\n");
}
return(0);
}
int main()
{
int i, j=0;
char string1[100],string2[100];
printf("Enter a sentence:\n");
fgets(string1,sizeof(string1),stdin);
sscanf(string1,"%c",&string1);
printf("Enter a second sentence:\n");
fgets(string2,sizeof(string2),stdin);
sscanf(string2,"%c",&string2);
/*uses the function for the strings below*/
begins(string1,string2);
return(0);
}
i dont know what to do, theres something wrong with my function. Any help would be great. thanks!