Find the first capital letter in a given string
C program to find the first capital letter in a given string.
Program
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
char str[MAX];
int i, flag;
printf("Enter the string\t:");
gets(str);
i = 0;
flag = 0;
while(str[i] != '\0')
{
if(str[i] >= 'A' && str[i] <= 'Z')
{
printf("\nFirst Capital letter '%c' found at position %d",str[i],i+1);
flag = 1;
break;
}
i++;
}
if(flag == 0)
{
printf("\nCapital letter not found");
}
getch();
}
Output
Enter the string :welcome to courseCRUX.com
First Capital letter 'C' found at position 18