This question requires writing a program to find a specified character in a given string.
Input format:
The first line of input is a character to be searched. The second line is a non-empty string (not more than 80 characters) ending with a carriage return.
Output format:
If found, output the maximum subscript corresponding to the character in the string in the format "index = subscript" in one line (subscript starts from 0); otherwise, output "Not Found".
Input sample 1:
m
programming
Output sample 1:
index = 7
Input sample 2:
a
1234
Output sample 2:
Not Found
title collection complete works portal
#include <stdio.h>
#include <string.h>
int main()
{
char ch, a[81];
int flag = 0;
ch = getchar();
getchar();
gets(a);
for (int i = strlen(a) - 1; i >= 0; i--)
if (a[i] == ch)
{
printf("index = %d", i);
flag = 1;
break;
}
if (flag == 0)
printf("Not Found");
return 0;
}