We will get a series from the user, we will throw the A-Z capital letters to another series and print it on the screen.
In fact, its logic is very simple. While navigating the items in the array with the 'for' loop, if A-Z detects letters, it assigns it to the new array.
1) Let's add our Standard Input / Output library and add our initial function:
#include <stdio.h>
int main()
{
2) Create the arrays and variables:
char arr[100], uppercaseletters[50];
int i=0, j=0;
//We created the variables 'i' and 'j' to navigate the characters of our series.
3) Let's get the array from the user:
printf("Enter array: ");
scanf("%s",&arr);
4) Let's create our loop, first return 'i = 0' and the number of items in the array.
The number of items in the array can be found with -strlen or -arr [i]! = '\ 0'.
for(i=0;arr[i]!='\0';i++)
{
5) Let's add the condition to the loop.
If the 'i' element is greater than A and less than Z, add it to the other array.
if(arr[i]>='A'&& arr[i]<='Z')
{
uppercaseletters[j++] = arr[i];
//The reason we do 'j++' is to add to the 0th element of the array at first and it will be 'j = 1', then it will add to the 1st element and it will continue as 'j = 2'.
}
}
6) Let's print our upper case array on the screen.
Also, the number of items in our array was 'j'.
for(i=0;i<j;i++)
{
printf("\n%c",uppercaseletters[i]);
}
//FİNİSH
return 0;
}
7) I hope this helps ...
#include <stdio.h>
int main()
{
char arr[100], uppercaseletters[50];
int i=0, j=0;
//We created the variables 'i' and 'j' to navigate the characters of our series.
printf("Enter array: ");
scanf("%s",&arr);
for(i=0;arr[i]!='\0';i++)
{
if(arr[i]>='A'&& arr[i]<='Z')
{
uppercaseletters[j++] = arr[i];
//The reason we do 'j++' is to add to the 0th element of the array at first and it will be 'j = 1', then it will add to the 1st element and it will continue as 'j = 2'.
}
}
for(i=0;i<j;i++)
{
printf("\n%c",uppercaseletters[i]);
}
//FİNİSH
return 0;
}
My English is not so good :)