Question: Write the code for a program that counts the number of 'A' characters in a character array you define in a 30-character program and writes
Write the code for a program that counts the number of 'A' characters in a character array you define in a 30-character program and writes all characters after the last 'A' character into another array.
(I want to use this code in Dev C++ compiler,please let the code language be "C")
! I would be very happy if you code it in a different way than the coding I mentioned below. !
#include
int main() { char input[30]; char output[30]; int i = 0, j = 0, countA = 0;
printf("Enter a string (up to 29 characters): "); fgets(input, 30, stdin); // Reads up to 29 characters + newline
// Remove the newline character if present int newlineIndex = 0; while (input[newlineIndex] != '\0' && input[newlineIndex] != ' ') newlineIndex++; if (input[newlineIndex] == ' ') input[newlineIndex] = '\0';
while (input[i] != '\0') { if (input[i] == 'A') { countA++; j = 0; } else if (countA) { output[j++] = input[i]; } i++; } output[j] = '\0';
printf("A's: %d, After Last A: %s ", countA, output); return 0; }
30 karakterden oluan programda tanmladnz bir karakter dizisi ierisinde 'A' karakter saysn sayan ve son 'A' karakterden sonraki tm karakterleri baka bir dizi ierisine yazan program kodunu yaznz
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
