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 yaznzStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started