Question

In: Computer Science

Write in C Language Write all these code in one program and upload. Consider this array...

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 .

Solutions

Expert Solution

#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.


Related Solutions

In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
Language: c++ works in visual basic Write a program that uses an array of nested structs...
Language: c++ works in visual basic Write a program that uses an array of nested structs to store the addresses for your store’s customers.  Each customer has a name and two addresses: home address and business address.  Each address has a street, city, state, and zip code. Requirements: 1. Data structure a. Define an Address struct with street, city, state and zip fields b. Define a Customer struct with lastNm and firstNm fields, plus homeAddr and busAddr fields...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
in C programming language Write a function removeDups that removes all duplicates in a given array...
in C programming language Write a function removeDups that removes all duplicates in a given array of type int. Sample Test Case: input -> {1,2,2,2,3,3,4,2,4,5,6,6} output -> {1,2,3,4,5,6,0,0,0,0,0,0} More specifically, the algorithm should only keep the first occurance of each element in the array, in the order they appear. In order to keep the array at the same length, we will replace the removed elements with zeros, and move them to the end of the array.
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The program then calls the foo function. The function will modify the array x of size n by doubling any values in x that are less than the threshold. The function will count how many values were changed and how many were not changed via two reference parameters. The function signature is: void foo(int n, int x[], int threshold, int *pChanged, int *pUnchanged); The function...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into...
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into your Arduino #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT