I have array in which I enter number of elements, enter all the elements, print them, and after that I should transfer all the capital letters into the new array, and small letters into another array, allocate memory for them and print it. I've tried it this way but it didn't worked:
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, j, counter=0, counter1=0;
char *arrA, *arrB, *arrC;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter elements of array: \n");
arrA = (char*)malloc(n * sizeof(char));
for (i = 0; i < n; i++) {
scanf(" %c", &arrA[i]);
}
for (i = 0; i < n; i++) {
printf("%d. element of array is: %c\n", i + 1, arrA[i]);
}
arrB = (char*)malloc(counter * sizeof(char));
arrC = (char*)malloc(counter1 * sizeof(char));
for (i = 0; i < n; i++) {
if ((arrA[i] >= 'A') && (arrA[i] <= 'Z')) {
counter++;
*arrB = *arrA;
}
}
for (i = 0; i < n; i++) {
if ((arrA[i] >= 'a') && (arrA[i] <= 'z')) {
counter1++;
*arrC = *arrA;
}
}
for (i = 0; i < counter; i++) {
printf("%d. element of array B is: %c\n", i + 1, arrB[i]);
}
for (i = 0; i < counter1; i++) {
printf("%d. element of array C is: %c\n", i + 1, arrC[i]);
}
free(arrA);
free(arrB);
free(arrC);
return 0;
}
How can I separate those capital letters into the new array "arrB"?