Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Iterative statement



Working with switch case



" ; " after loop



Specifer



Test expression




String_ sentence case in a string




// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include #define pf printf #define MAX 1000 int main() { char str[MAX]; int i; //input string pf("Enter a string: "); scanf("%[^\n]s",str); //read string with spaces //capitalize first character of words for(i=0; str[i]!='\0'; i++) { //check first character is lowercase alphabet if(i==0) { if((str[i]>='a' && str[i]<='z')) str[i]=str[i]-32; //subtract 32 to make it capital continue; //continue to the loop } if(str[i]=='.') //check end line ( " . " fullstops) { //if end line ( " . " fullstops) is found, check next character ++i; //check the space if(str[i]==' ') { //if space found check next character ++i; //check next character is lowercase alphabet if(str[i]>='a' && str[i]<='z') { str[i]=str[i]-32; //subtract 32 to make it capital continue; //continue to the loop } } } else { //all other uppercase characters should be in lowercase if(str[i]>='A' && str[i]<='Z') str[i]=str[i]+32; //subtract 32 to make it small/lowercase } } pf("\nThe Capitalize string of each sentence is:\n %s",str); return 0; }
OUTPUT:


© 2018 - All rights reserved