Using C. Please fill out the following code and do not any any additiona headers
ID: 3891393 • Letter: U
Question
Using C. Please fill out the following code and do not any any additiona headers. The prompt is below.
#include <stdio.h>
#include <stdlib.h>
char toUpperCase(char ch){
/*Convert ch to upper case, assuming it is in lower case currently*/
}
char toLowerCase(char ch){
/*Convert ch to lower case, assuming it is in upper case currently*/
}
int stringLength(char s[]) {
/*Return the length of the string*/
}
void camelCase(char* word){
/*Convert to camelCase*/
}
int main(){
/*Read the string from the keyboard*/
/*Call camelCase*/
/*Print the new string*/
return 0;
}
Write a function void camelCase(char* word) where the argument of the function is a string that must consist of two or more words separated by one or more underscores such as "random_word" or "this_ is_my_first_programming assignment". camelCase(.) should remove underscores from the sentence and rewrite it in "lower camel case (A naming convention of the CamelCase family in which several words are joined together, where the first letter of the entire word is lowercase, but subsequent first letters are uppercase)" (https://en wikipedia.org/wiki/Camel_case). Watch out for the end of the string, which is denoted by 10". You also have to make sure that an user provided input string is in valid form first before you use it for the function camelCase(.). Below are some examples of the conversions that are expected a)" random-word" should be changed to "random word" first. b) "@Srandom4word" should be changed to "random_word" first. c) " random word should be changed to "random_word" first. d) "random word" should be changed to "random_word" first. e) "RANDOM_Word" should be changed to "random_word" first. f One or more combinations from options a, b, c, d and e. The strings that you must not allow as arguments are- " " " " " ", "435 %7 SS", "random", " random ". Print "invalid input string" for such cases. You are allowed to limit the size of the input string you will provide. Finally, do not use the library functions isupper(), islower(..) or strlen(.) Write the functions on your own to perform such operations (10 pts will be deducted if you have done so).Explanation / Answer
here is your program : --------->>>>>>>>>>
#include <stdio.h>
#include <stdlib.h>
char toUpperCase(char ch){
/*Convert ch to upper case, assuming it is in lower case currently*/
return (char)((int)ch - 32);
}
char toLowerCase(char ch){
/*Convert ch to lower case, assuming it is in upper case currently*/
return (char)((int)ch + 32);
}
int stringLength(char s[]) {
/*Return the length of the string*/
int i = 0;
while(s[i] != ''){
i++;
}
return i;
}
void camelCase(char* word){
/*Convert to camelCase*/
int n = stringLength(word);
char *temp = (char *)malloc(sizeof(char) * (n+1));
int i = 0,j;
int st = 0;
for(j = 0;j<n;j++){
if(st == 0){
if(word[j] == ' ' || word[j] == '@' || word[j] == '_' ){
}else{
if((int)(word[j]) >= 65 && (int)(word[j]) <= 91){
temp[i++] = toLowerCase(word[j]);
st = 1;
}else if((int)word[j] >= 95 && (int)word[j] <= (95+26)){
temp[i++] = word[j];
}
}
}else{
if((int)(word[j]) >= 65 && (int)(word[j]) <= 91){
temp[i++] = toLowerCase(word[j]);
}else{
if(word[j] == ' '){
temp[i++] = '_';
st = 0;
}else{
temp[i++] = word[j];
}
}
if(word[j] == '_'){
st = 0;
}
}
}
if(st == 0){
printf(" Invalid Input String");
return;
}
temp[i] = '';
printf(" %s",temp);
}
int main(){
/*Read the string from the keyboard*/
/*Call camelCase*/
/*Print the new string*/
char arr[201];
printf(" Enter a String : ");
fgets(arr,200,stdin);
camelCase(arr);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.