Just modify the code in Part C in the following manner: 1. int array[8] should be replaced by the char array[] = “EENG112 Introduction to Programming” 2. modify call_by_reference array so that its input is char* and it modifies its input as follows: a. Each vowel is replaced by a character “1”, b. Each consonant is replaced by a character “0”. 3. print_1D_array should be modified to print the character sequence. Keep the original form of code in Part C, just make required modifications.
#include <stdio.h>
#include <conio.h>
void pass_by_reference(char *,int );
void print_1D_array(char*,int );
void print_1D_array_adress(char* ,int );
int count(char x[]);
char v[] = "AEIOUaeiou";
char c[] = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
int main()
{
char *array_p;
char array[] = "EENG112 Introduction to Programming";
array_p = array;
int x;
x=count(array);
printf("Before modification:\n");
printf("%s", array);
pass_by_reference(array_p,x);
printf("\nAfter modification:\n");
print_1D_array(array_p,x);
printf("\nAddresses of elements of array:\n");
print_1D_array_adress(array,x);
getch();
return 0;
}
int count(char x[])
{
int i=0;
while(x[i]!='\0')
i++;
return i;
}
void pass_by_reference(char *p,int N)
{
int i,j;
for(j=0; j<N; j++) {
for(i=0; v[i]!='\0'; i++) {
if(p[j]==v[i])
p[j]=1;
}
for(i=0;c[i]!='\0'; i++){
if(p[j]==c[i])
p[j]=0;
}
}
}
void print_1D_array(char* array,int N)
{
for (int i = 0;i<N;i++)
{
printf("%d ",*(array+i));
}
printf("\n");
}
void print_1D_array_adress(char* array,int N)
{
for (int i = 0;i<N;i++)
{
printf("%p\n",array+i);
}
printf("\n");
}
Comments
Leave a comment