I am currently trying to get the program to search for more than one character. This has been successful up to a certain stage.
For some reason the program is reading the count for the first character and the second the same. I have looked through the code a few times and still stuck. Any help would be much appreciated
Here is the code.Code:#include<stdio.h>
int main(void)
{
int array[100], search, c, n, count = 0;
int search2, c1, n1, count2 = 0;
printf("Enter the number of elements in array\n");
scanf("%d",&n);
printf("Enter %d numbers\n", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d",&array[c]);
for ( c1 = 0 ; c1 < n ; c1++)
printf("Enter the number to search\n");
scanf("%d",&search);
printf("enter second number to search\n");
scanf("%d", &search2);
for ( c = 0 ; c < n ; c++ )
for ( c1 = 0; c1< n ; c1++)
{
if ( array[c] == search )
if ( array[c1] == search2)
{
printf("%d is present at location %d.\n", search, c+1);
count++;
printf("%d is present at location22i3rwefkhc %d.\n", search2, c1+1);
count2++;
}
}
if ( count2 == 0 )
printf("%d is not present in array.\n", search2);
else
printf("%d is present %d times in array.\n", search2, count2);
if ( count == 0 )
printf("%d is not present in array.\n", search);
else
printf("%d is present %d times in array.\n", search, count);
return 0;
}