Write a program in C Language that gets a string from the user. it then performs
ID: 3719026 • Letter: W
Question
Write a program in C Language that gets a string from the user. it then performs the following tasks using a pointer to the input string:1. Replace every space character by the newline character
2. Count the number of lower a character
Please start with #include <stdio.h> Write a program in C Language that gets a string from the user. it then performs the following tasks using a pointer to the input string:
1. Replace every space character by the newline character
2. Count the number of lower a character
Please start with #include <stdio.h> Write a program in C Language that gets a string from the user. it then performs the following tasks using a pointer to the input string:
1. Replace every space character by the newline character
2. Count the number of lower a character
Please start with #include <stdio.h>
Explanation / Answer
//Write a program in C Language that gets a string from the user. it then performs the following tasks using a pointer to the input string:
//1. Replace every space character by the newline character
//2. Count the number of lower a character
//Please start with #include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void replaceSpaceByNewline(char string[]){
char *ptr = string;
for ( ; *ptr != ''; ptr++) {
if(*ptr == ' '){
*ptr = ' ';
}
}
}
int countLowerACharacter(char string[]){
char *ptr = string;
int count = 0;
for ( ; *ptr != ''; ptr++) {
if(*ptr == 'a'){
count++;
}
}
return count;
}
int countLowerCharacter(char string[]){
char *ptr = string;
int count = 0;
for ( ; *ptr != ''; ptr++) {
if(islower(*ptr)){
count++;
}
}
return count;
}
int main(){
char string[MAX];
//scanf("%s", string)
fgets(string, MAX, stdin);
printf("string is: %s ", string);
size_t len = strlen(string);
if (len > 0 && string[len-1] == ' ') {
string[--len] = '';
}
replaceSpaceByNewline(string);
printf("string is: %s ", string);
printf("the count having letter 'a' in string is %d ",countLowerACharacter(string));
printf("the count having lower letters in string is %d ",countLowerCharacter(string));
printf(" bye");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.