TheNNS 112

plagiarize

TheNNS 112 Nearly a Posting Virtuoso

Basically I need to read from a text file that looks like this

customer Kevin
checking myaccount 100.00
bond mybond1 1997 100 0.07
bond mybond2 2010 200 0.01
irabond myirabond1 1997 100 0.06
end
customer Mark
irabond hisirabond1 1999 200 0.08
bond hisbond1 1990 2000 0.10
end

I need to get each customers info, name, account names and balance, etc into an object. This I know how to do. What I don't know how to do is break up the text file to allow this.

Here's what I have so far:
[CODE]

include "stdafx.h"
include
include
include
include
include

using namespace std;

int main()
{
ifstream in_file;
string file_name;
string temp;
string allText;
cout<<"Please enter the file name: ";
cin>>file_name;

bool loop = true;

//stringstream ss;

in_file.open(file_name);

while(in_file>>temp)
{
    stringstream ss;
    ss << temp;
    while(loop)
    {
        string st;
        ss >> st;
        if (st =="end")
        {

            loop = false;

        }
        if (st == ""){loop = false;}
        allText += st;
    }
    loop = true;
}

system ("pause");

}

[/CODE]
I can get a string of words until the word "end", which is what I want, but I'm confused as to where to go next. How to I get the cusomter name? I guess I could look for customer in the string and say, delete customer, but store the next word into this vector. Then look for the word checking, delete it and store the name, etc into this vector and so on.

Would this work? How would ...

TheNNS 112

That's how I originally did it, but found out we had to use a vector of char*'s instead of strings. I like your code better though, much simpler.

TheNNS 112

Just though I'd let every know that I finished this lab, so we can close this thread, or at least stop posting in it. Here's my final solution.
[CODE]

include "stdafx.h"
include
include
include
include
include
include

using namespace std;

int main()
{
//reads in the text file
ifstream in("const.txt");
//each word read int he document gets stored in temp
string temp;
//used to add a word to a vector or a counter
bool add = true;
//vector of strings used in parallel with phrase
vector words;
//stores each word used in the text
vector<char *> phrase;
//stores the coutners for the words used
vector count;

//reads in a word at a time
while(in>>temp)
{
    //gets rid of punctuation ',' '.' ';' and/or paranthesis
    for (int i = 0; i < temp.size(); i++)
    {
        if (temp[i] == ',' || temp[i] == '.' || temp[i] == ';' || temp[i] == '(' || temp[i] == ')' || temp[i] ==':')
        {
            temp = temp.erase(i);
        }
    }
    //sets all characters to lowercase to compare words
    for (int i = 0; i < temp.size(); i++)
    {
        temp[i] = tolower( (unsigned char) temp[i] );
    }
    //vect.push_back(temp);
    stringstream convert(temp); // stringstream used for the conversion initialized with the contents of Text
    int Result;
    if ( (convert >> Result) )
    {
        //if string is a number, do nothing
    }
    //if it's not a string, copy it to the vector
    else
    {

        /*I know this is weird, but it makes sense to me. ...

TheNNS 112

Yeah, I don't know why he wants to do all this crap. Apparently we'll learn maps next semester but that seems like it's so much faster.
Now that I have everything working, the vector of char*s, and the parallel vector of ints, I'm going to find the largest 10 values in the int vector and print those out with their word counterparts.

any good way to do this? I was thinking of iterating through the vector of ints like this

int tempCnt = 0;
int mostUsed[10];
[CODE]for (int i; i < count.size(); i++)
if (count[i] > tempCnt)
tempCnt = count[i];
mostUsed[0] = tempCnt;

[/CODE]

This will only get the largest element, not the top ten, and I'm sure there a better way than having 10 if statements.

TheNNS 112

This is my code so far. I know I have a lot of unused variable and a lot of weird comments, but it works.
[CODE]int main()
{
ifstream in("const.txt");
string temp;
bool add = true;
vector words;
vector<char > phrase;
vector count;
int counter = 0;
//phrase[0] = "";
int v = 5;
int
p = &v;
int a = p;
char
cstr;
//char b = &v;
while(in>>temp)
{
//gets rid of punctuation ',' '.' ';' and/or paranthesis
for (int i = 0; i < temp.size(); i++)
{
if (temp[i] == ',' || temp[i] == '.' || temp[i] == ';' || temp[i] == '(' || temp[i] == ')' || temp[i] ==':')
{
temp = temp.erase(i);
}
}
//sets all characters to lowercase to compare words
for (int i = 0; i < temp.size(); i++)
{
temp[i] = tolower( (unsigned char) temp[i] );
}
//vect.push_back(temp);
stringstream convert(temp); // stringstream used for the conversion initialized with the contents of Text
int Result;
if ( (convert >> Result) )
{
//if string is a number, do nothing
}
//if it's not a string, copy it to the vector
else
{
/
This puts the words 'temp' into the string vector*/

        /*this puts the pointer for 'temp' into the char* vector*/

        char * writable = new char[temp.size() + 1];
        std::copy(temp.begin(), temp.end(), writable);
        writable[temp.size()] = '\0'; // don't forget the terminating 0

        // don't forget to free the string after finished using it
        //char * testStr = temp.c_str();
        //phrase.push_back(testStr);

        //checks for the word in the ...

TheNNS 112

any one? please?

TheNNS 112

that's just evil man

jingda commented: You're back;) +0

TheNNS 112

[QUOTE]Why are you using a char*? If you are working with strings why not use the std::string?[/QUOTE]
Because it's for a class and they want us to learn the least efficient way possible.

This is what I have so far
[CODE] ifstream in("const.txt");
string temp;
vector words;
vector<char> phrase;
vector count;
int counter = 0;
while(in>>temp)
{
//gets rid of punctuation ',' '.' ';' and/or paranthesis
for (int i = 0; i < temp.size(); i++)
{
if (temp[i] == ',' || temp[i] == '.' || temp[i] == ';' || temp[i] == '(' || temp[i] == ')')
{
temp = temp.erase(i);
}
}
//sets all characters to lowercase to compare words
for (int i = 0; i < temp.size(); i++)
{
temp[i] = tolower( (unsigned char) temp[i] );
}
//vect.push_back(temp);
stringstream convert(temp); // stringstream used for the conversion initialized with the contents of Text
int Result;
if ( (convert >> Result) )
{
//if string is a number, do nothing
}
//if it's not a string, copy it to the array
else
{
words.push_back(temp);
char
place;

        //phrase[0]= &temp;
        for (int i = 0; i < phrase.size(); i++)
        {
            phrase[i] = (char*) malloc (i+1);
        }   
    }
}[/CODE]

So I now have a vector of lowercase words with no punctuation. I need to store these memory addresses in a char* vector. What is the syntax for that?

TheNNS 112

thanks for your replies. So far, my program will read all of the words from the text file correctly. The next thing I need to do is allocate memory for each file and save the pointers in a vector char. Does any one know the syntax to do that?

Here's is some pseudo code/c++ code

[CODE]
vector <char*> words;
while(there are words, keep reading them)
{
words.push_back(word pointer);
}
[/CODE]

Is this correct?
What is the proper syntax?

TheNNS 112

holy crap, every one should chill out. Seriously, this is a 5 year old thread I started when I was young and dumb. I remember that job and it was an unpaid internship. During down times, my coworker and I would try to mess with each other. That was a crap long time ago.

sergent commented: xD +0
happygeek commented: Well said sir! +0

TheNNS 112

I thought windows was written in c though, not basic.

TheNNS 112

so how do i make it read the next line with text? how will it skip blank lines?

TheNNS 112

[QUOTE]Well first off you never reset you loop variable to true after you exit your while loop.[/QUOTE]
Why do I need to do that? It's supposed to read characters until it gets to an empty space, then it reads the next one, and so on. But it makes sense to use [CODE] while(getline (myFile,line))[/CODE] instead.
[QUOTE]As a side note how are you going to handle punctuation marks?[/QUOTE]
I'm thinking I'll get rid of punctuation and replace uppercase with lowercase letters.

TheNNS 112 Nearly a Posting Virtuoso

This is a somewhat big project for me as I'm not very experienced in c++. The end goal is to read a text file, and read every word in the text file. Each time a new word is read, store it in a vector. If a word is repeated, keep a counter for how many times the word was used.
Right now, I have code that is supposed to read every word, and then give me a final count on the total number of words. For some reason it reads the first 4 and then stops.

Can any one help me see my problem? Thanks in advance
[CODE]

include "stdafx.h"
include
include
include
include

using namespace std;

int main()
{
int i = 0;
bool loop = true;
string line;
stringstream ss;
string output;
ifstream myFile ("const.txt");
if (myFile.is_open())
{
while(myFile.good())
{
getline (myFile,line);
ss << line;

        while (loop)
        {
            std::string st;
            ss >> st;
            i++;
            output+=st+" ";
            if (st == "")
            {
                loop = false;
            }
        }
    }
    myFile.close();
    cout << output << endl;
    cout << "number of words " << i;
}
else cout << "unable to open";

system ("pause");

}

[/CODE]

This is the output that I get
[CODE]Provided by USConstitution.net
number of words 4Press any key to continue . . .[/CODE]
And here is the text file I'm reading from
[url]http://www.usconstitution.net/const.txt[/url]

TheNNS 112 Nearly a Posting Virtuoso

In my c++ class we are assigned to make a piglatin translator. I haven't had much experience with c++, but I've done quite a bit of programming in other languages.
My main question would be what functions are available in c++ to handle strings and change them?
I have a basic idea of how my program will work, but I'm not familiar with how c++ handles strings and how they can be changed. After a few google searches all I've come up with is that you can change strings according to character number.
Does anybody have any better ideas?

TheNNS 112

thanks for the tajendra, it works great.

TheNNS 112

Ok, I feel like an idiot now. This is way easier to do than it sounds. I just used two for loops and that did the trick. I just need to get rid of the commas at the end and I should good. Here's the code I used.
[CODE] if (myfile.is_open())
{
for (int k = 0; k < 20; k++)
{
for (int i = 0; i < 20; i++)
{
myfile << temp[0+k][0+i] << ",";
}
myfile << endl;
}
}
else cout << "Unable to open file";[/CODE]

TheNNS 112 Nearly a Posting Virtuoso

I have a 2D array with generated doubles. I need to write this array to a CSV file so that I can open it in Excel. Is there a method or function in C++ that allows for this to be done? I could do it manually, but it would take a lot longer. Any help is appreciated, thanks.

TheNNS 112

I have the facebook app on my phone. When I go to work, I turn it off. problem solved.

TheNNS 112

give it all - rise against.

TheNNS 112

[QUOTE]1) When and why did you begin doing computer programming?[/QUOTE]
10th grade. I was 15 and took a "computer programming class at my high school. Actually 8th grade if you count html as a programming language.
I wanted to do something with computers and this was the only interesting elective my high school offered.
[QUOTE]2) What role did boredom have in setting you on a computer developer path?[/QUOTE]
Boredom had very little with me beginning programming, but now when I get bored I add more functionality to my website with PHP.
[QUOTE]
3) What factors do you think influence people to become malicious hackers? Where is the tipping point for this?[/QUOTE]
In my opinion, people become hackers for various reasons. As we've seen with the attacks from anonymous and lulzsec, they're extreme activists trying to get attention. If we look at GeoHot, who jailbroke the PS3 and iphone, he just wanted a challenge. Now he works for facebook.
And then you have the hackers that steal people's credit card information. All of these motives are very different, and I doubt they were motivated by boredom. Hacking is extremely slow and would bore some one to death.

TheNNS 112

[quote]Maybe the fact that there is no semi-colon ending line 175 might have something to do with it!?[/quote]

holy freaking crap, i'm retarded. Thanks man.

TheNNS 112

honestly learn some self control, it's not that hard. I've trained myself to only use it at home, and only when I have some free time, not every single freaking minute of every day, and even then I browse around for maybe 10 minutes tops. It's great tool to keep in touch with people who live far or out of the country. I rarely use it to talk to my friends who live close. That's what phones and real life are for. But seriously, learn some self control!

TheNNS 112

Python is super easy to learn and can do a ton.

TheNNS 112

[QUOTE]1. How did you become an IT Pro?[/QUOTE]
School, jobs, lots and lots of DIY projects, countless hours on daniweb and other forums, patience, and a hate for IE6 and perl.
[QUOTE]2. Why did you become an IT Pro?[/QUOTE]
I suck at everything else
[QUOTE]3. Do you love what you do?[/QUOTE]
Absolutely. It's fun trying to figure out new solutions to problems everyday.

TheNNS 112

bluehost.com works great. unlimited storage and bandwidth for $5 per month. They also have really good management tools.

TheNNS 112 Nearly a Posting Virtuoso

Ok, so I this error on one of my PHP pages.
Parse error: syntax error, unexpected T_PRINT in /var/www/html/texas/z_code/wells_edit.php on line 177

I have no idea what i'm doing wrong and I've been trying to figure this out for some time. If any one could help me, that would be great.

And sorry for the crappy formatting, it's just how my boss wants it done.

[CODE]<?php
include("../z_includes/header.php");
include("../z_includes/db_connect.inc");
include("../z_includes/queries.php");
include("../z_includes/makeCalendar.php");
?>

TheNNS 112

Arkinder, the code you provided was for images. It doesn't work with videos. When I embed videos and click on them it loads forever, but never plays.
also this is taken from lightbox2's website

[quote]Can I display flash, video, or other content using the script?
Sorry, photos only. For other content, google for Lightbox modifications or try an alternative script such as Cody Lindley's ThickBox.[/quote]

TheNNS 112

[code]

            <param name="movie" value="/movies/movie.ogv">
            </object>

[/code]
this doesn't work. What's wrong with it?