Created
January 20, 2014 20:47
-
-
Save Zulqurnain/0601a6d0398f147137bd to your computer and use it in GitHub Desktop.
C code to take paragraph as an input from user and do the following: 1.count total number of character 2.count total number of spaces 3.count total number of string (are)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<conio.h> | |
| void main(void){ // by zulqurnain jutt | |
| char* arr=new char[200]; // you can use pointer for longer strings | |
| printf("\n::Start Entering Your Paragraph Now::\n\t"); | |
| int i=0,j=0,NoofChars=0,Noofspaces=0,NoofStrings=0; | |
| while(arr[i]=getch()){ | |
| if(arr[i]!=13){ | |
| // escape sequence \n can't be used as '\n' in this case so use its Ascii 13 | |
| printf("%c",arr[i]); | |
| i++; | |
| continue; | |
| } | |
| else{ | |
| arr[i]='\0'; | |
| break; | |
| } | |
| } | |
| printf("\n"); | |
| i=0; | |
| for(;arr[i]!=0;i++,NoofChars++){ | |
| if(arr[i]==' '){ | |
| Noofspaces++; | |
| } | |
| if(arr[i]==' '&&((arr[i-1]>=65 &&arr[i-1]<=90)||(arr[i-1]>=97 && arr[i-1]<=122))){ | |
| NoofStrings++; | |
| } | |
| } | |
| NoofStrings++; // last word | |
| printf("Total Characters :=: %d\nTotal Strings:=: %d\nTotal Spaces:=: %d\n",NoofChars,NoofStrings,Noofspaces); | |
| getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment