So the task at hand is that I need to make a code to input firstly the minimal size of two arrays. Then the condition for array A is that it should only input lowercase letters and for array B just letters, uppercase and lowercase included. Afterwards I need to scan both arrays for triplets of inserted letters and then see whether the subsets of 3 are equal for both arrays and then make a substring for it. While scanning uppercase and lowercase letters should be treated as same so I wanted to use strcmpi but I was not able to so I used strcasecmp.
For example I have arrayA=(a s d r e d b l u)
and arrayB=( d B l u a s d R e d)
so the substring would look like this substring=(red blu)
as red
and blu
are both the same triplets for both arrays
I cannot use break or go to or switch, that is what our teacher said, and we also cannot input this array as a string as we need to input it as char type. If anyone can give any input I would be glad as I do not know how to proceed. I assumed I should maybe use gets because, even though I do not have syntax errors, it does not exit the input after I press space or enter.
#include <stdio.h>
#include <string.h>
int main()
{
int i=0,j=0,s,m,n;
char nizA[100], nizB[100], podstring[100], pom, niz1p[100], niz2p[100];
printf("Enter the minimal value of array A\n");
scanf("%d",&m);
printf("Enter the minimal value of array B\n");
scanf("%d",&n);
do{
printf("Enter elements of array A\n");
for(i=0;nizA[i]<m;i++)
{
scanf("%c",&nizA[i]);
if (nizA[i]<'a' && nizA[i]>'z')
{
i--;
printf("The required condition is not met.");
}
}
}while(nizA[i]<'a' && nizA[i]>'z');
do {
printf("Insert elements of the array B:\n");
for(j=0;nizB[j]<m;j++)
{
scanf("%c",&pom);
if (nizA[i]<'a' && nizA[i]>'z' || nizA[i]<'A' && nizA[i]>'Z')
{
nizB[j]=pom;
}
else
{
j--;
}
}
}while(nizA[i]<'a' && nizA[i]>'z' || nizA[i]<'A' && nizA[i]>'Z');
printf("Entered array A is:\n");
printf("%c",nizA[i]);
printf("Entered array B is\n");
printf("%c",nizB[j]);
for(i=0;nizA[j]<m;i++)
{
for(j=0;nizB[j]<m;j++)
{
niz1p[0]=nizA[i];
niz1p[1]=nizA[i+1];
niz1p[2]=nizA[i+2];
niz2p[0]=nizA[i];
niz2p[1]=nizA[i+1];
niz2p[2]=nizA[i+2];
if (strcasecmp(niz1p,niz2p))
{
podstring[s+1]=nizA[i];
podstring[s+2]=nizA[i+1];
podstring[s+3]=nizA[i+2];
}
}
}
printf("The substring is\n");
printf("%c",podstring[s]);
}