Hi ,
How can we input a string without specifying its length before ? As in , the program should understand that the string has ended when the return key has ended.
The input string can be a line , word , blog , novel[It can be that big I mean to say]
Apart from that how to count the number of words , vowels and other things in the string.Please help me ASAP!
Software/Hardware used:
?
ASKED:
March 7, 2010 12:41 PM
UPDATED:
March 8, 2010 5:57 PM
Homework questions are not supported here. Sorry.
excuse me? This is not a homework question!
Well, it looks like one. Specially this part:
“As in , the program should understand that the string has ended when the return key has ended”
Here are some hints:
-You will need to use pointers
-You will need to use the new and delete operators.
-You will probably need to use the strlen function
-You will probably need to use the getche() function or similar.
-The ascii code for ENTER is 13
-You will probably need to use loops to count words, vowels, etc.
h>
#include <string.h>
#include <conio.h>
using namespace std;
int main ()
{
int a=0;
string str;
cout << “Enter string (EOL = $) : “;
getline (cin, str, ‘$’);
cout << “Str is : ” << str << endl;
}
See m using this , but how should I count the number of words in str.
just tell me how to enter a string of unknown length !! and how to use it further..don’t tell me how to count vowels and everything .
If you are using the string class, you should not worry about the string length, as you don’t have to declare its length beforehand.
If you were using pointers to chars, then the string length would matter.