Friday, October 30, 2009

Chap9[D]c Converting all lowercase to uppercase in string

Write a program that converts all lowercase characters in a given string to its equivalent uppercase character.

void main()
{
char word[30];
int i=0;

printf("\nType a word with capital and small letters");
scanf("%s",word);


while(word[i]!='\0')
{

if(word[i]>=97&&word[i]<=122)
word[i]-=32;

i++;
}

printf("\nThe edited word is %s",word);
}

1 comment:

  1. #include ;

    char lower_to_upper(char ch1)
    {
    char ch2;

    if(ch1 >= 'a' && ch1 <= 'z'){
    ch2 = ('A' + ch1 - 'a');
    return ch2;
    }
    else{
    ch2 = ch1;
    return ch2;
    }
    }

    int main()
    {
    char lower, upper;

    printf("Please input a lowercase character: ");
    scanf("%c", &lower);

    upper = lower_to_upper(lower);

    printf("nThe uppercase equivalent is: %cn", upper);
    return 0;
    }

    ReplyDelete