473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

help with string sparsing.

ok guys this is like my last resort im already 1 day late on this project and i really cant afford to drop this class this block im in datastructers which is kickin my butt already but anyway help if you can and i will really appreciate it.

heres the project...

Your task, in this first iteration, is to write a program that parses user input. There are some basic <<verb>> <<noun>> and <<verb>> <<adverb>> <<noun>> combinations that you should address. See the above text for examples. What I want this project to do is to take user input and show, on the screen the parsed (or tokenized) list of inputs. For example, if the user enters: Take Letter. I want to see on the screen:
<< verb>> Take
<<noun>> Letter
If the user enters Attack Troll with Sword, I want to see on the screen:
<<verb>> Atack
<<noun>> Troll
<<adverb>> With
<<noun>> Sword.
This program MUST use a free function called UserInput. This is a simple project designed to get you back into the mood of programming. This project MUST be done in the Unix environment


heres the code i already have, it compiles and sparses the words perfectly but doesnt input the noun, verb, adverb oart. i also have to put in a loop that will run the program until the user asks to exit. im not at all askin anyone to do this program for me but any help would be greatly appreciated. you have no idea. thanks in advance guys and gals.



#include <iostream>
#include <string>

using namespace std;

void UserInput(string &out);

int main()
{

//do{

string max;
UserInput(max);

return(0);

} //Closes main

void UserInput(string &max)
{

char input[80];
char newstring[4][80];
int wordCount = 0;
int NewWordCounter = 0;
int NumberOfWords = 0;



for(int rowCount = 0; rowCount < 5; rowCount++)
{
for(int ColCount = 0; ColCount < 81; ColCount++)
newstring[rowCount][ColCount]='X';

}

cout<<"> ";
cin.getline(input, 80);


// This for loop takes a two-dimensional array of characters and parses it into tokens

for(int x = 0; x < 80; x++) // 80 possible characters on a line
{
newstring[wordCount][NewWordCounter]=input[x]; // newstring[0][0] to the first character
if(input[x] == ' ')
{
NumberOfWords++;
newstring[wordCount][NewWordCounter]='\0'; // we have to enter the string terminator
wordCount++; // since I hit a space - I must be onto a new word
NewWordCounter = -1; // This is used for the row of my newstring 2D array
}
NewWordCounter++;

if(input[x]=='\0')
break; // Why keep going if I have reached the last character -- let's break
}

cout<<"There are "<<NumberOfWords + 1<<" words in the string. They are: "<<endl;

for (int counter = 0; counter < NumberOfWords + 1; counter++)
{
cout<<newstring[counter]<<endl;
}


}
//while(UserInput != exit);
Nov 21 '06 #1
0 1196

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
1
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
6
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.