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

C++ Language Write a program that reads the numbers.txt file and stores it into an array...
C++ Language Write a program that reads the numbers.txt file and stores it into an array of integers. Use the sample functions in the text and in the notes from chapter 8 to sort the array in ascending order (low to high). You can use either method (bubble or selection sort) to accomplish this. Then store the sorted array into an output file sorted Numbers.txt. There are 100 values both positive and negative integers in this file.
Using C language: Write a program that asks the user for the size of an array,...
Using C language: Write a program that asks the user for the size of an array, then reads a number of integer values (from user input) into the array. Write a function to print out the array and call it to print the array out after all values are read in. Write a function to implement Insertion Sort and run it on the data array to sort the array. Write another function to implement Selection Sort and run it on...
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...
Write a C-based language program in visual studio that uses an array of structs that stores...
Write a C-based language program in visual studio that uses an array of structs that stores student information including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,”). Write the same program in the same language without using structs.
Write a Y86 program in C language that sorts an array of data using Bubble Sort....
Write a Y86 program in C language that sorts an array of data using Bubble Sort. Allow the user to input up to 10 numbers from the keyboard. Sort the array in place (i.e., no need to allocate additional memory for the sorted array). Your program should be a complete one
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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT