In: Computer Science
Write in C Language
Write all these code in one program and upload.
Consider this array
char address1 [ ] = "12330 Washington Blvd, suite 300, Sacramento, CA 94560-2341" ;
(NOTE: The constant string on the RHS gets copied into the array address1 on the LHS)
1. Write a piece of code to count only letters in the string address1 using the function isAlpha
2. Convert to all Upper Case
Write a program to convert address1 to all uppercase letters using toupper function
3. Write a program to count only the digists in the address1 array.
4. Declare
char address2 [ 100 ];
Copy only letters and digits (use isalnum function) from Address1 to address2 .
#include <stdio.h> #include <ctype.h> int main(void) { char address1 [ ] = "12330 Washington Blvd, suite 300, Sacramento, CA 94560-2341" ; int numLetters = 0; int i = 0; while(address1[i]) { if(isalpha(address1[i])) { numLetters++; } i++; } printf("Total number of alphabets: %d\n", numLetters); //convert to all uppercase. i = 0; while(address1[i]) { if(isalpha(address1[i])) { address1[i] = toupper(address1[i]); } i++; } printf("After converting to uppercase: %s\n", address1); int numDigits = 0; i = 0; while(address1[i]) { if(isdigit(address1[i])) { numDigits++; } i++; } printf("Total number of digits: %d\n", numDigits); char address2 [ 100 ]; i = 0; int j = 0; while(address1[i]) { if(isalnum(address1[i])) address2[j++] = address1[i]; i++; } address2[j] = '\0'; printf("Address2: %s\n", address2); return 0; }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.