int main() { string input; cout<<"Enter a String:" ; cin>>input; cout<<"the number of characters:"<<input.length()<<endl;
return 0; }
this programme also works but only for single words for example: bangladesh, india, computer, science etc...but it is not applicable for counting characters from long sentences
#include using namespace std; int main( ) { char aub[]="Unable to read....";; cout << "Please enter your string: "; cin >> aub; cout << "Your name is: " << sizeof(aub) << endl; }
some lines are funny to look as like cout << "Your name is: " << sizeof(aub) << endl; Not an appropriate caption/label of cout. Advice: Use profile picture and full name.
Name-Main Uddin Batch-46 ID-201421090 Program:Write a c++ program to count number of character in a given string
#include #include #include using namespace std; int main(){ int charcnt=0,i; string str; // clrscr(); cout<<"Please type in a string:" ; getline(cin,str); //printf("\n\nEntered String is \" %s \" \n",str); for(i=0;str[i]!='\0';i++){ } charcnt=i; cout<<"Number of Characters:"<<charcnt<<endl;
Name-M.R.Awal Hossain ID-201421092 Batch-46 #include #include #include using namespace std; int main(){ int Char=0,R; string namestr; // clrscr(); cout<<"Please type in a string:" ; getline(cin,namestr); //printf("\n\nEntered String is \" %s \" \n",str); for(R=0;namestr[R]!='\0';R++){ } Char=R; cout<<"Number of Characters:"<<Char<<endl;
Very good information and thanks for posting this here! Please keep sharing more information like this further in future. You can find more information on C++ Tutorials in the following link.
#include
ReplyDelete#include
using namespace std;
int main()
{
string input;
cout<<"Please type in a string:" ;
getline(cin,input);
int numOfchars=input.length();
for(unsigned i=0; i<input.length(); i++)
{
if(input.at(i)== ' ')
{
numOfchars--;
}
}
cout<<"Number of Characters:"<<numOfchars<<endl;
return 0;
}
noted
Delete#include
ReplyDelete#include
using namespace std;
int main()
{
string input;
cout<<"Enter a String:" ;
cin>>input;
cout<<"the number of characters:"<<input.length()<<endl;
return 0;
}
this programme also works but only for single words
for example: bangladesh, india, computer, science etc...but it is not applicable for counting characters from long sentences
noted. but it is risky to use in exam. you can use only, if examiner advised you to use built-in function in c
Delete#include
ReplyDeleteusing namespace std;
int main( )
{
char aub[]="Unable to read....";;
cout << "Please enter your string: ";
cin >> aub;
cout << "Your name is: " << sizeof(aub) << endl;
}
some lines are funny to look as like
Deletecout << "Your name is: " << sizeof(aub) << endl;
Not an appropriate caption/label of cout.
Advice: Use profile picture and full name.
Name-Main Uddin
ReplyDeleteBatch-46
ID-201421090
Program:Write a c++ program to count number of character in a given string
#include
#include
#include
using namespace std;
int main(){
int charcnt=0,i;
string str;
// clrscr();
cout<<"Please type in a string:" ;
getline(cin,str);
//printf("\n\nEntered String is \" %s \" \n",str);
for(i=0;str[i]!='\0';i++){
}
charcnt=i;
cout<<"Number of Characters:"<<charcnt<<endl;
getch();
}
Noted. Found Correct. You are advised to use profile picture
DeleteDear Sir, Please visit:
ReplyDeletehttp://itlearn24.blogspot.com/2014/11/count-number-of-character.html
found correct
DeleteName-M.R.Awal Hossain
ReplyDeleteID-201421092
Batch-46
#include
#include
#include
using namespace std;
int main(){
int Char=0,R;
string namestr;
// clrscr();
cout<<"Please type in a string:" ;
getline(cin,namestr);
//printf("\n\nEntered String is \" %s \" \n",str);
for(R=0;namestr[R]!='\0';R++){
}
Char=R;
cout<<"Number of Characters:"<<Char<<endl;
getch();
}
noted
DeleteThis comment has been removed by the author.
ReplyDeleteMohammad Ashraful Hasan sobuj
ReplyDeleteCSE-46(Dip)
ID=201420656
#include
#include
using namespace std;
int character (values v)
{
int charnum=v.size();
for(char i=0; i> v
getline(v);
character(v);
return 0;
}
Dear Sir, I have upload full program but not show some this program
ReplyDelete#include
ReplyDelete#include
using namespace std;
int character (string s)
{
int charnum=s.size();
for(char i=0; i<s.size(); i++)
{
if(s.at(i)== ' ')
{
charnum--;
}
if(s.at(i)== '.')
{
charnum--;
}
}
cout<<endl<<"Enter string has "<<charnum <<" Characters:"<<endl;
}
int main()
{
string s;
char i;
cout<<"Please type in a string: " ;
getline(cin,s);
character(s);
return 0;
}
Very good information and thanks for posting this here! Please keep sharing more information like this further in future. You can find more information on C++ Tutorials in the following link.
ReplyDeleteLearn Cpp online