Create qz5.c to include all of the following function prototypes:
void check1(char *, char, int *);
void check2(char *, char, int *);
void display(char, int);
Then, implement main() to perform the tasks below:
check1() must use the pointer given in its first parameter and no direct access of the array to set a value to its third parameter, which can then be accessed by main().
//******************************************************START OF PROGRAM*****************************************
#include <stdio.h>
void check1(char *, char, int *);
void check2(char *, char, int *);
void display(char, int);
void main(){
char str[10] = {"HomeworkLibster"}, *ptr, letter;
int n = 0; //used to keep track of how many elements grater than or
less than input letter is in array
printf("\nEnter the letter to be compared");
scanf("%c", &letter);
ptr = str; // ptr is a pointer pointing to the array str
check1(ptr, letter, &n);
display(letter, n);
check2(ptr, letter, &n);
display(letter, n);
}
void check1(char *ptr, char letter, int *n){
*n = 0; //since n is a pointer, we have to use value at operator
'*' to access its value
for(int i = 0; i < 9; i++)
if(ptr[i] < letter)
(*n)++;
}
void check2(char *ptr, char letter, int *n){
*n = 0; //since n is a pointer, we have to use value at operator
'*' to access its value
for(int i = 0; i < 9; i++)
if(*(ptr + i) < letter) //uses i as a displacement for accessing
values from ptr
(*n)++;
}
void display(char letter, int n){
printf("\nThere are %d elements in the given array lesser than '%c'
and %d elements equal to or greater than '%c'", n, letter, 10 - n,
letter);
}
//*****************************************************END OF PROGRAM*****************************************************
The above is the implementation of the functions check1() and check2()
check2() uses its character pointer (ptr) in a different way than check1(), because it uses the value at operator '*' and the displacent 'i' to calculate the address of each of its elements and then display its value - *(ptr + i)
Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *);...
implement the following function: void BuildString(int argc, char* argv[]); 1. Arguments passed through the function. Concatenate the strings arguments using strcat, display the concatenated string. 2.. If only one argument passed, display the string. 3. If no argument passed, display the message, no argument passed. In main do the following: 1. Call the function BuildString, passing the proper arguments (argc and argv).
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
C++
The Function's Specification You will be writing a function with this specification: void quicksort void* base size t n, size t bytes, int compar (const void* const void*) Precondition base is a pointer to the first component of an array with at least n elements The component type of the array may be any type at all, and the parameter bytes must be the number of bytes in each component of the array. The fourth parameter compar, must be...
must be done in C
You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...
The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc is greater or equal to 3. • If it is not, then print the following message: Incorrect number of arguments - please call with assignment min max where assignment is the name of your executable and min/max define the range of numbers for your array. • If argc is ≥ 3 convert the values for min and max into integers and store them in...
in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed. Call a function called makeArray to define an array of integers with the number of elements equal to the number of students surveyed. Call a function called getStudentData to allow the user to enter the number of hours each student spent watching Netflix into the array. Call a function called getAverage to calculate and display the average of the hours entered. Call a function called...
Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...
Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...
#include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...
C++ Array Expander and Element Shifter Thank you so much to anybody that can help! Here are our two homework prompts: PART A: Array Expander Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0....