Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-06-2004, 04:26 PM   #1 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
Question 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?
Androto is offline   Reply With Quote
Old 10-06-2004, 06:06 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 10-06-2004, 06:17 PM   #3 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
what does
Code:
for(;;)
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];
      }
   }
Androto is offline   Reply With Quote
Old 10-06-2004, 06:20 PM   #4 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
i tried running the program, and all i got was a empty window.
Androto is offline   Reply With Quote
Old 10-06-2004, 06:20 PM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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
__________________
Valmont is offline   Reply With Quote
Old 10-06-2004, 06:22 PM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 10-06-2004, 06:22 PM   #7 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
k, but when you get back tomorrow, you'll know that i don't have any books.
Androto is offline   Reply With Quote
Old 10-06-2004, 06:24 PM   #8 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Goto http://www.cplusplus.com/doc/tutorial/ and start learning
__________________
Valmont is offline   Reply With Quote
Old 10-06-2004, 06:30 PM   #9 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
i'll take a look at the site.

which time zone do you live in?
Androto is offline   Reply With Quote
Old 10-06-2004, 06:41 PM   #10 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Usually CET but at the moment GMT.
__________________
Valmont is offline   Reply With Quote
Old 10-07-2004, 12:37 PM   #11 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 10-07-2004, 01:36 PM   #12 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
No.
Add ONE letter PER line!
On the last line enter a @ .
__________________
Valmont is offline   Reply With Quote
Old 10-11-2004, 06:15 PM   #13 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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)?
Androto is offline   Reply With Quote
Old 10-12-2004, 01:58 AM   #14 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 10-12-2004, 01:04 PM   #15 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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];
....
}
Androto is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Need help on program B00tleg Standard C, C++ 1 10-12-2004 12:02 AM
Help on interest program B00tleg Standard C, C++ 2 10-07-2004 08:50 PM


All times are GMT -8. The time now is 11:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting