Function customToUpper

Function customToUpper: The function/method customToUpper accepts three arguments – strfromChar and toChar representing a string value and two lower case alphabets respectively.

The function/method customToUpper must modify the string str by converting the lower case alphabets that occur between fromChar and toChar in the English alphabet set(both inclusive) to upper case.

Your task is to implement the function customToUpper so that it passes all the test cases.

Note: The fromChar always occurs before the toChar in the English alphabet set.

IMPORTANT: Do not write the main() function as it is already defined.

Example Input/Output 1:
Input:
MicTesting#One#Two#Three
a m

Output:
Modified String: MICTEstInG#OnE#Two#THrEE

#include <stdio.h>
#include <stdlib.h>
 void customToUpper(char str[], char fromChar, char toChar)
 {
 int asciiFrom = (int)(fromChar);
 int asciiTo = (int)(toChar);
 int i;
 for(i=0;i<strlen(str);i++){
   int currentCharAscii = str[i];
     if(isalpha(str[i]) && currentCharAscii>=asciiFrom && currentCharAscii<=asciiTo)
     {
         str[i]=toupper(str[i]);
     }
 }
 }
 int main()
 {
     char str[101], fromChar, toChar;
     scanf("%sn%c %c", str, &fromChar, &toChar);
     customToUpper(str, fromChar, toChar);
     printf("Modified String: %s", str);
     return 0;
 }
Previous Article

Smaller of Two Numbers (Using Ternary Operator)

Next Article

Area of Circle

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *