/* Processing A Paragraph */ #include<stdio.h> #include<conio.h> void getNumberOfWords(char*); void capitalizeFirstWord(char*); void replaceWord(char*); void main(){ char string[100]; int choice; clrscr(); printf("Enter a Paragraph..\n"); gets(string); clrscr(); printf("Entered Para is...\n"); puts(string); printf("\nwhat you want to do with this para?"); printf("\n1.Find the total number of words."); printf("\n2.Capitalize the first word of each sentence."); printf("\n3.Replace a given word with another word."); printf("\nEnter Your Choice..."); scanf("%d",&choice); switch(choice){ case 1:getNumberOfWords(string);break; case 2:capitalizeFirstWord(string);break; case 3:replaceWord(string);break; default:printf("\nYou Have Entered a Wrong Choice"); } getch(); } void getNumberOfWords(char *string){ int i,count=0; for(i=0;string[i] != '\0';i++){ if(string[i]==' ') count++; } printf("\nNumber of word in the given para is...%d",count+1); } void capitalizeFirstWord(char *string){ int i; for(i=0;string[i] != '\0';i++){ if(i==0 || string[i-1]=='.'||string[i-2]=='.'){ while(string[i] !=' ' ){ if((string[i]>='a' && string[i]<='z')) string[i]=string[i]-32; i++; } } } printf("\nCapitalized Para...\n"); puts(string); } void replaceWord(char *string){ int i=0,j=0,k=0,lenOfString,noOfWords; char oldWord[20],newWord[20],word[200][20]; printf("\nEnter the word that you want to replace..."); scanf("%s",&oldWord); printf("\nEnter the replacement word..."); scanf("%s",&newWord); lenOfString=strlen(string); for(k=0;k<lenOfString;k++){ if(string[k]!=' '){ word[i][j]=string[k]; j++; } else{ word[i][j]='\0'; j=0; i++; } } word[i][j]='\0'; noOfWords=i+1; for(i=0;i<noOfWords;i++){ if(strcmp(word[i],oldWord)==0){ strcpy(word[i],newWord); } printf("%s ",word[i]); } }