C program to Capitalize the String
Capitalize a String or a sentence means to make the first letter of each word upper case.
We try to achieve the same using the C program here
*************************PROGRAM************
We try to achieve the same using the C program here
*************************PROGRAM************
#include <stdio.h>#define MAX 100int main(){char str[MAX]={0};int i;//input stringprintf("Enter a string: ");scanf("%[^\n]s",str); //read string with spaces//capitalize first character of wordsfor(i=0; str[i]!='\0'; i++){//check first character is lowercase alphabetif(i==0){if((str[i]>='a' && str[i]<='z'))str[i]=str[i]-32; //subtract 32 to make it capitalcontinue; //continue to the loop}if(str[i]==' ')//check space{//if space is found, check next character++i;//check next character is lowercase alphabetif(str[i]>='a' && str[i]<='z'){str[i]=str[i]-32; //subtract 32 to make it capitalcontinue; //continue to the loop}}else{//all other uppercase characters should be in lowercaseif(str[i]>='A' && str[i]<='Z')str[i]=str[i]+32; //subtract 32 to make it small/lowercase}}printf("Capitalize string is: %s\n",str);return 0;}
*************************OUTPUT*******************************
First run: Enter a string: HELLO FRIENDS HOW ARE YOU? Capitalize string is: Hello Friends How Are You? Second run: Enter a string: hello friends how are you? Capitalize string is: Hello Friends How Are You? Third run: Enter a string: 10 ways to learn programming. Capitalize string is: 10 Ways To Learn Programming.
Hey you can use toupper in c
ReplyDeleteHere are some good suggestions also check for
fresh2refresh
veewom
scholarsoul
hackerrank (practice)
leetcode (practice)