|
 |
|
 |
10-06-2004, 04:26 PM
|
#1 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Help for another program
does anyone know how to read in a steam of charactes, on after another, one at a time, and build a sentence out of them. Then print out the sentence, as well as a list of all the letters that appeared in the sentance as well as how many times they each appeare?
|
|
|
10-06-2004, 06:06 PM
|
#2 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Quote:
|
does anyone know how to read in a steam of charactes, on after another, one at a time, and build a sentence out of them
|
Is this what you mean?
Code:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string letters;
string input;
unsigned count(0);
for(;;)
{
//Use getline so spaces and tabs are counted in.
getline(cin, input, '\n');
if(input[0] == '@') //@ terminates the input sequence.
break;
else
{
//Add only ONE single letter. Ignore the rest.
letters+=input[0];
}
}
cout<<letters<<endl;
system("PAUSE");
return 0;
}
If so, then try the rest of your assignment for yourself first. It's a nice excercise.
__________________
|
|
|
10-06-2004, 06:17 PM
|
#3 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
what does mean?
what does
Code:
getline(cin, input, '\n');
mean? i've never used getline before.
don't understand this part either:
Code:
if(input[0] == '@')
break;
else
{
letters+=input[0];
}
}
|
|
|
10-06-2004, 06:20 PM
|
#4 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
i tried running the program, and all i got was a empty window.
|
|
|
10-06-2004, 06:20 PM
|
#5 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Then study this part from your books. These are the very basics. If you can't figure out what they all mean, then you're not ready for this particular assignment to start with.
I am tired and it is bloody late here. It is almost today in fact. Tomorrow I *might* be answering this. I gotta go now zzzZZZzz 
__________________
|
|
|
10-06-2004, 06:22 PM
|
#6 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Quote:
Originally posted by Androto
i tried running the program, and all i got was a empty window.
|
Offcourse you got an empty window.
You wanted to input a stream char by char. So I assume you need to enter char by char. When you are done entering the individual characters, enter @ and <enter>. Then see what happens.
__________________
|
|
|
10-06-2004, 06:22 PM
|
#7 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
k, but when you get back tomorrow, you'll know that i don't have any books.
|
|
|
10-06-2004, 06:24 PM
|
#8 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
__________________
|
|
|
10-06-2004, 06:30 PM
|
#9 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
i'll take a look at the site.
which time zone do you live in?
|
|
|
10-06-2004, 06:41 PM
|
#10 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Usually CET but at the moment GMT.
__________________
|
|
|
10-07-2004, 12:37 PM
|
#11 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
when i ran the progam and typed in random letters followed by the @ on the next line, all it did was give me the first letter of the string.
|
|
|
10-07-2004, 01:36 PM
|
#12 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
No.
Add ONE letter PER line!
On the last line enter a @ .

__________________
|
|
|
10-11-2004, 06:15 PM
|
#13 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
is there a way for the person running the program to just type in the name, then when the hit enter (i'm guessing you have to use the getline thing for this part) it says how many times each letter appears (I think i'll have to use an array for this part)?
|
|
|
10-12-2004, 01:58 AM
|
#14 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Yes offcourse there is a way. You gave the solution basically yourself. I'll do it later. In the mean time see how far you can get.
__________________
|
|
|
10-12-2004, 01:04 PM
|
#15 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
would i be able to use this in it, or would this be wrong?
Code:
int main()
{
char sentance[x];
string x;
cin >> sentance[x];
....
}
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:18 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|