Killer_Typo 82 Master Poster

>size_t size = strlen(reverse);
For starters, you need to include <cstring> to use the C-style string functions.

>char * getwords = new char();
This is the cause of your undefined behavior. You allocated one character. Only one. That means you can only store one character, ever. But look here:

thanks, i had wondered how to allocate more instead of using a constant char foo[100]; i thought maybe that was the solution, if not i will ask around :)

>cin.getline(getwords,100);
You're telling getline that it can store up to 100 characters in getwords. This is called buffer overflow, and it's undefined. That's a very bad thing.

very much so :)

>cin.sync();//clean up buffer for next example
sync isn't required to do what you think it does. An extremely knowledgeable person explained why here. ;)

will read, i remember someone posting about using cin.flush to remove any characters from the buffer in case a user entered in more than was allocated but i tried that and got errors :(

I'm not a huge fan of stdafx.h either, but I can let that slide.

yeah i didnt want to include it, i checked the box to remove pre-compiled headers but i guess i have no say in that when using the express version of VC++.

oh and by the way, when i was researching this in google a few links to daniweb popped up, and of course you were the one responding and …

Killer_Typo 82 Master Poster

>the words reversed but their location is intact?
The other way around. "hello world" would become "world hello".

oohhhh awesome. cool i will work on that then.

quick question though.

would you consider the ' ' to be the delimeter for a word; furthermore, what about hyphinated words. words broken apart by hyphens or a string of words connected by them. are they to be considered as one whole word or should they be split in the process.

Killer_Typo 82 Master Poster

>simple and it works
Your code exhibits undefined and implementation-defined behavior (start a new thread asking why if you want details). It also alters the words, which won't work for us, we need the words to be reversed without also reversing the characters in each word. But it's a start.

cool i started a new thread.

so from what i am gathering if i were to input the string

hello world

you dont want

dlrow olleh

you want

olleh dlrow

the words reversed but their location is intact?

:)

i figure i should ask questions now rather than later :P

iamthwee commented: I hope you are joking, how does "reverse words" mean reverse "letters" :D +12
Killer_Typo 82 Master Poster

started a new thread because naru got my interest. please explain.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void reverseword(char * reverse) {
    size_t size = strlen(reverse);              //get the size of the char *
    for(size_t i = 1; i <= size; i++)     
    {
        cout << reverse[size - i];                  //output the word
    }
}
void reverseword (string reverse) {
    size_t size = reverse.size();
    string::reverse_iterator walkword;
    for(walkword = reverse.rbegin(); walkword < reverse.rend(); walkword++)
    {
        cout << *walkword;
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Method one for string reversal" << endl;
    cout << "==============================" << endl;
    cout << "== Using Char * and cin.getline" << endl;
    cout << "== using for statement to itterate" << endl;
    cout << "==============================" << endl;
 
    char * getwords = new char();       //will hold the words
    cout << "Please enter the words to reverse" << endl << endl << endl;
    cin.getline(getwords,100);           //get the word(s) to reverse
    reverseword(getwords);      //reverse the words
    cin.sync();//clean up buffer for next example
 
    cout << endl << endl << endl;
    cout << "Method Two for string reversal" << endl;
    cout << "==============================" << endl;
    cout << "== Using std::basic_string cin.getline" << endl;
    cout << "== using build in itterator members" << endl;
    cout << "==============================" << endl;
 
    string getwordsagain;
    cout << "Please enter the words to reverse" << endl << endl << endl;
    getline(cin, getwordsagain);
    reverseword(getwordsagain);
    cin.sync();                 //clean the buffah
    return 0;
}

cheers!

Killer_Typo 82 Master Poster

simple and it works :)

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void reverseword(char * reverse) {
    size_t size = strlen(reverse);              //get the size of the char *
    for(size_t i = 1; i <= size; i++)     
    {
        cout << reverse[size - i];                  //output the word
    }
}
void reverseword (string reverse) {
    size_t size = reverse.size();
    string::reverse_iterator walkword;
    for(walkword = reverse.rbegin(); walkword < reverse.rend(); walkword++)
    {
        cout << *walkword;
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Method one for string reversal" << endl;
    cout << "==============================" << endl;
    cout << "== Using Char * and cin.getline" << endl;
    cout << "== using for statement to itterate" << endl;
    cout << "==============================" << endl;
 
    char * getwords = new char();       //will hold the words
    cout << "Please enter the words to reverse" << endl << endl << endl;
    cin.getline(getwords,100);           //get the word(s) to reverse
    reverseword(getwords);      //reverse the words
    cin.sync();//clean up buffer for next example
 
    cout << endl << endl << endl;
    cout << "Method Two for string reversal" << endl;
    cout << "==============================" << endl;
    cout << "== Using std::basic_string cin.getline" << endl;
    cout << "== using build in itterator members" << endl;
    cout << "==============================" << endl;
 
    string getwordsagain;
    cout << "Please enter the words to reverse" << endl << endl << endl;
    getline(cin, getwordsagain);
    reverseword(getwordsagain);
    cin.sync();                 //clean the buffah
    return 0;
}

i know of a few things i could do to optimize but for the question it works...or so i …

Killer_Typo 82 Master Poster

because i happen to think you are one of the brighter minds i have met in a while i will take you up on your challenges. i will post back shortly with some code :-D

Killer_Typo 82 Master Poster

standard arrays are not needed either.

yay, good for you now post something productive or stop harping.

Killer_Typo 82 Master Poster

No containers (vectors) or the like are necessary.

maybe not, but i happen to have a project already open where i was using vectors so i wrote this while i was in the middle of my project.

the same logic could easily be applied to standard arrays ;)

Killer_Typo 82 Master Poster

try this method instead. worked much better for me

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
int main ()
{
   vector<string> names(2);
   names[0] = "robert";
   names[1] = "Michael";
   for (int i = 0; i < int(names.size()); ++i)
   {
      for (int n = 0; n < int(names[i].size()); ++n)
      {
         cout << (names[i]).at(n) << endl;  //outputs each letter in each name on a new line just for testing purposes
      }
   }
}
Killer_Typo 82 Master Poster

since you are using VC++ i am assuming you arein the .NET framework?

do you happen to be working with windows forms?

System::Windows::Forms

if so then you can capture keyboard input very easy on any form.

Killer_Typo 82 Master Poster

try doing a reinterpret cast

reinterpret_cast<new data type> (expression to convert)

or you may have some data wrong

Killer_Typo 82 Master Poster

http://www.connectionstrings.com/?carrier=pervasive

you are still going to need to go to pervasives website and download the appropriate driver to use and furthermore you should configure/test the driver.

Killer_Typo 82 Master Poster

so lets say you have an array of names and you want to itterate through all of the names and each letter in the name

string allnames[20];  //lets say we have 20 names
 
for(int i = 0; i < 20; ++i)
{
  //get the length of the names
int namelength = allnames[i].size();
string currentname = allnames[i];
for(int n = 0; n < namelength; ++n)
{
   currentname[n]; //do your magic
   //this line actually grabs the character at the n'th position
}
}
Killer_Typo 82 Master Poster
int main()
{
    ////////////////////////////////////
    //
    //Fun With Vectors
    //
    ////////////////////////////////////
    //creating vectors
    //vectors are created like so
    //vector< datatype > variable name(size)
    //if the size is not included a vector of zero elements is created
    //an int vector with size defined
    vector<int> vec1(10);
    //an int vector without size defined
    vector<int> vec2;
    //adding elements to vector with size defined
    vec1.at(0) = 5;             //vector size is 10 (0-9)
    vec1[1] = 10;               //vector size is 10 (0-9)
    vec1.push_back(20);         //new vector size is 11 (0-10)
    /*
        quick break to note the above statement
        ---------------------------------------
        the size changed because push_back can be used to add elements
        to the end of the vector.  Thus causing the vectors size to change
    */
 
    //adding elements to a vector without size defined
    vec2.push_back(4);          //vector size is now 1 
    vec2.push_back(10);         //vector size is now 2 (0-1)
    vec2.at(1) = 10;            //vector size is still 2 but i have modified position 1 of the vector
    vec2[0] = 10                //vector size is still 2 but i have modified position 0 of the vector
    /*
        quick break to note the above statement
        ---------------------------------------
        the at() method can only be used on a vector after it has been given
        some data.  If not it will throw an error because the vector and has a size of 0
    */
    //resizing already sized vector
    vec1.resize(20);        //data within the vector is preserved
    //resizing vector with no initial size
    vec2.resize(15);        //data within the vector is preserved
    //itterating through a vector using while
    vector<int>::iterator vec1walk = vec1.begin();
    while (vec1walk …
Killer_Typo 82 Master Poster

These aren't examples of quines though - To qualify as a quine, the program must be able to replicate its own source code without any input (either from a file, the keyboard, or anywhere else)

see here for a little more info http://en.wikipedia.org/wiki/Quine_%28computing%29

shhhh we're having fun over here :)

the quine page i posted was pretty decent and has examples for a ton of languages should check it out as well :)

Killer_Typo 82 Master Poster

http://www.cplusplus.com/

great resource, i use it for the most part.

Killer_Typo 82 Master Poster

ok what are you two arguing for. I have neither VC++ nor Bloodshed. BORLAND C++ is the best!!

hehehe i think you win :)

look up the sexually transmitted library (STL)

and the namspace std

along with vectors

very good read and you will learn much in doing so.

the standard template library introduces a lot of functionality.

http://www.sgi.com/tech/stl/stl_introduction.html

Killer_Typo 82 Master Poster

Dev is better for pure c++, VS tends to convolute what is standard c++. Such as when killer typo mistook

for each

As standard c++.

heh it's actually because of a setting in VS which can be turned off to disable ;)

dont try and set the standard with my mistake that would be a mistake in itself :)

i've asked a couple professionals (30+ years experience in software/hardware..etc development, one of which is currently head of product research development) and when i asked about the compiler they use, they replied that they use microsofts products.

when i asked about other compilers, like borland, turbo, bloodshed they just laughed them off.

Killer_Typo 82 Master Poster

I have dev-c++ but I didn't use it because it didn't support graphics

could always work with Visual Studio

i happen to find this environment quite fun and easy to work in.

Killer_Typo 82 Master Poster

vectors are much like arrays

#include <vector>
int main()
{
//standard way to create an array
int myarray[someconstsize] = { 0 }; //assigns all values to default zero
 
//vector declaration
vector<int> myvec;//declares an int type vector
 
//adding data to them
 
myarray[0] = 4;
 
myvec.push_back(4); //adds four to the end

this is in no ways the end all be all deffination, but a somewhat decent look at em :)

iamthwee commented: You explanations are sooo cute! +12
Killer_Typo 82 Master Poster

as long as the code.cpp file is located with the exe it will output whatever the source file is.


works well

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
 ifstream openfile("./string_manip.cpp", ios::in);
 string linefromfile;
 while ( getline(openfile, linefromfile) )
 {
  cout << linefromfile << endl;
 }
 openfile.close();
 return 0;
}
Killer_Typo 82 Master Poster

I tried it in my computer.

#include<iostream.h>
main(){char*s="#include<iostream.h>%cmain(){char*s=%c%s%c;cout.form(s,10,34,s,34,10);}%c";
cout.form(s,10,34,s,34,10);}

As you said a string C is created and the code is written to it.
But I thought that in a quine it automatically reads your code and displays it.

Here we write the code into the C variable.But suppose the code is very big, then we can't type everything into this variable.

cout.form didn't work for me either. I use borland C++

hehe if you want it to read a very large C++ file then just create an IO stream to read the CPP file contents and display them.

infact on the quine page i linked it is really nothing more than a trick here or there. for people using PHP they reccomend using PHP's ability to read files and have it read itself and output that.

Killer_Typo 82 Master Poster

hey,
I tried with what you have said i saved the command in notepad as bat file then run it , i didnt get expected result ?
It is openning up a command prompt and the the command which i have saved

what do you mean by it is opening up the command prompt with the command you have entered?

it should open the prompt and run the command you have entered.

if that is what it is doing then it has worked :P

here is what i just did to test

open notepad > [Windows Key] + R
in the prompt type> Notepad
Press the [Enter] Key

type in the simple command

dir | more  
#the directory command piped through more
#piping through more allows the user to read a screenfull
#of information at a time

file>Save

File Type>All File Types

Name>anything you want.bat

(it is important to have the BAT extension)

run the file from anywhere (command prompt works best)

should get the directory contents of the current directory and stop at each screenful.

Killer_Typo 82 Master Poster
#include<iostream.h>
main()
{
char*s="#include<iostream.h>%cmain(){char*s=%c%s%c;cout.form(s,10,34,s,34,10);}
%c";cout.form(s,10,34,s,34,10);}

char*s="#include<iostream.h>%cmain(){char*s=%c%s%c;cout.form(s,10,34,s,34,10);}%c";
cout.form(s,10,34,s,34,10);}


What is the logic behind this?

it is much easier to read if you add in all of the line breaks. they were removed in the examples to maintaine their quinness

the logic behind is simply that they are creating a char pointer "s" that contains all of the source in the document.

then using cout.form they print the output using formatting.

for some reason in VC++ i was unable to use cout.form but using printf worked just fine instead.

Killer_Typo 82 Master Poster

you dont need C++ to do this.

in fact running a shutdown on mass ammounts computers is better suited for a NT script.

you could just as easily write a bat file

shutdown -r -f -m \\192.168.1.104 -t 60

just open notepad, save as .bat and run it.

Killer_Typo 82 Master Poster
Killer_Typo 82 Master Poster

this thread is over two years old, please allow it to rest in peace.

Killer_Typo 82 Master Poster

http://www.connectionstrings.com/ the best damn link hands down in finding the right string to use to connect to a given array of database types.

Killer_Typo 82 Master Poster

EDIT: nvm i errd and missed part of his post :-X

Killer_Typo 82 Master Poster

PLEASE HELP....
I was wondering if someone could help me. I am taking a programming class and I am having alot of problems. When I began my class we were given a copy of Visual Studio 2003. I had alot of problems with it and when I would go to build everything would be fine. When I would click to start without debugging was the problem. At the beginning it asks you if you wish to continue but the code does not log off the program when you enter 'n' for some reason. When it goes to enter name of troop it works fine, but then it ends right there. It won't go any farther for some reason. So I downloaded a copy of Visual Studio 2005 and still no luck. I am supposed to be writing a summer fundraiser program for a Boy Scout troop. Each troops fundraising is done on a bonus program. For 300 cans they get 10 points, 301-600 they get 15 points, and 601 and up are 20 points. I can't figure out the code to tally the number of readers, total number of the cans, total number of bonus points, average number of cans, average number of points, and the highest number of points to a single troop.
I am having the hardest time in this class and it is the last class I need to finish. Please someone help??

I had a really hard time reading this, break up the post …

Killer_Typo 82 Master Poster

>learning both C and C++ is good but you may find yourself
>trying to unteach yourself things from C when you work in C++.
Yes, just like when you learn C++ and Java, C and C#, Java and Fortran, Perl and Python, LISP and Forth... Pick any combination of languages and your statement is absolutely true. So did you have a point or are you simply trying to propagate the usual C/C++ myths?

there are deffinate uses for both C and C++ but it is not necesarily true that one should learn C prior to C++ ;)

All that said, I would strongly suggest you learn all of the languages above well and not limit yourself to any one or two languages by also learning the .net

there have been numerous .NET jobs available lately. It seems as though businesses are picking up on the languages because of the little learning curve and they can have something visible (software wise) near immediate.

of course the tradeoff is the fact that somethings are best done through windows API not included in the .NET framework so one hase to call in the .DLL's through the use of the runtime.interopservices

Killer_Typo 82 Master Poster

here is how it looks in dotnet

private: System::Void combobox_onClick(System::Object^ sender, System::EventArgs^ e) {
    if ( combobox->selecteditem == "Square" );
       {
          //do your coloring inside here
       }
}

also, since it is a combo box i would use the selectedindexchange event

which is only going to be thrown each time the index changes instead of each time the control is clicked

private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
if ( comboBox1->SelectedItem == "FOO")
{
//do your magic here
}
Killer_Typo 82 Master Poster

The idea here is to make each character in the string exist in every position, for example:

string is "JOY"

so taking J:-
1st pass: "JOY"
2nd pass: "OJY"
3rd pass: "OYJ"

taking O:-
1st pass: "OJY"
2nd pass: "JOY"
3rd pass: "JYO"

taking Y:-
1st pass: "YOJ"
2nd pass: "JYO"
3rd pass: "JOY"

then remove the repeated results, and you'll get all the combinations for that string

great post.

actually gave me some ideas on how i would personally tackle this problem.

Killer_Typo 82 Master Poster

java compilers and the java runtime environment are created using C++


learning both C and C++ is good but you may find yourself trying to unteach yourself things from C when you work in C++.

Killer_Typo 82 Master Poster

http://www.daniweb.com/forums/thread82074.html

posted just a few below this.

as well as some good examples linked i believe.

Killer_Typo 82 Master Poster

you need to check to see which item has been selected

so when the event is raised do a check to make sure that the selected item is the right one.

Killer_Typo 82 Master Poster

post your current code for the entire file that is throwing the errors.

please wrap using

[ code="csharp" ]
[ /code ]

tags.

Killer_Typo 82 Master Poster

to get a random within a range

int min = 33;
int max = 127;
int range = (max - min) + 1;
 
//now generate some random numbers
int somerandomnum = min + (int)(range * rand() / (RAND_MAX + 1.0));
 
//method will always generate a random number within range
Killer_Typo 82 Master Poster

can you explain what foo is to me?
what will i have to do to write the pseudocode in c++?

what function can i use to help me find one letter, and read it's value?? this is all sort've confusing... I thought the basic file i/o system was complicated when i learned it..

'foo' and sometimes 'bar' are just used in psuedo code or examples instead of using actual names because the example given may have no actual context :)

'foo' could be replaced with 'realygigantvariablename' or even 'ilikepickles'

'foo' is like the variable x in math, just a place holder :)

to write psuedo code? nothing, just get wordpad and write it, psuedo code is just so you can get the basic idea of what you are doing without having to open up your compiler and waste time.

it is a good method to plan out your ideas.

no particular function.

lets say i've got the word "robertson"

i want to know how many o's are in the word...i could do this!

//assume standard includes ive used above
 
int main()
{
    string name = "Robertson";  
    int c = 0, //counter for the while  
        cMax = int (name.length()), //the length of the name so we can cache it  
        oCount = 0; //the number of o's found in the word   
    while ( c < cMax )  
    {    
        if ( char (towlower(name[c])) == 'o' ) //change the letter to lowercase and check to …
Killer_Typo 82 Master Poster

Sorry I wasn't more specific...

I use dev C++(which I love) , and it wasn't compiling.

I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.

I need some thing that will read the word "kodiak"
and spit out:

6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....

I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.

I am very grateful for you helping me become a better C++ programmer,

Kodiak

awesome you are on the right track

so if we have a statement to itterate through all of the letters in the word it is now about counting each of the letters as they appear :)

case/switch will work for this

psuedo code:

while counting through each letter in the word

check to see what letter you are

check to see if you are a letter (not a space or symbol)

if you are a letter determin which …

Killer_Typo 82 Master Poster

AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI.

well damn my compiler for giving me access to for each.

let's write a while statement then!

string foo = "super duper long string of wooorrrdddsss";
int c = 0;
while ( c < foo.length() )
{
  cout << foo[c];
  c++;
}
Killer_Typo 82 Master Poster

easy!!


this is more of a command shell question though :-/

seperate each command with the & symbol

use a && to ensure that the following command is only run if the previous was successful

so to go up a directory and get the contents

system("cd .. && DIR");
 
//or
 
system("cd .. & DIR");

the only difference is that the first version only executes if the initial cd .. executed correctly else it will not continue the second version executes each command no matter what.


BTW a good read http://207.46.196.114/windowsserver/en/library/44500063-fdaf-4e4f-8dac-476c497a166f1033.mspx?mfr=true

Killer_Typo 82 Master Poster

thanks, but that code didn't work.... maybe explain to me how to use it??

didnt work how so?

didnt work as in it wouldnt compile?

or didnt work as in it wouldnt count the letters?

make sure you are including the right files to use strings from the standard type libraries

#include <iostream>
#include <cstdlib>
using namespace std;
 
int main()
{
  string mystring = "hello world";
  for each (char letter in mystring)
  {
     cout << letter << endl;
  }
}

will output

h
e
l
l
o
 
w
o
r
l
d
Killer_Typo 82 Master Poster

have you thought of contacting webroot or other online licenses companies to see if they would be interested in selling your product.

if it sells good enough it could easily make it into stores in more locations than you could wing on your own and they would handle all of the legal overhead as they are the distributer.

Killer_Typo 82 Master Poster

thanks alot!!! now i just need a way to compare letters...!! thanks!!!!!!!!!!!!

counting letters is quite easy, you can easily take a string of foo length and run a foreach on it

string foo = "some string of some length";
 
for each ( char letter in foo )
{
  cout << letter << endl;
}

i have the logic already written up for counting letters but you should play around with it some more before i hand the code over :-D

Killer_Typo 82 Master Poster

FIXED!

//get the length of a string using the sexually transmitted library
#include <iostream>
#include <cstdlib>
using namespace std;
 
int main()
{
  string foo = "mystring";
  cout << foo.length();
}

EDIT: because i only have so long to edit i may have to double post to get some more info in thurr.

Killer_Typo 82 Master Poster

Just to clear up the air - When a string is inputed like below

Hello world! // The 3rd l, the space, the char r and the exclamation mark - must all be deleted and the string should the be like:

Helowold //then
Heowld //then
Hewl

cool well now you have more than enough to begin work on your version, post your snippits along with questions and others along with myself will try to answer any questions :)

Killer_Typo 82 Master Poster

sub / super pshhh it was a typo :P

look at what time i posted it. LOL

Killer_Typo 82 Master Poster

what he mean is using C++ language n code.. what is the dif.. how can i change it

from what i understand C++ is a subset of C so all C code should compile in a C++ compiler.

without going through your code line by line i guess it would be a matter of changing how data is cast and how pointers are handled (slight differences)

Killer_Typo 82 Master Poster

Thank you very much. Appreciated.

I think the function will reach to zero time on sunday. That is what it does. It does not change

But can you please suggest how can I make this function more efficient as it is not very efficient with the use of too many while loops.

the most efficient method is going to entail determining the difference between what you have and what zero is and then subtracting by that ammount instead of continually removing one unit at a time.

so if you have 42 seconds instead of just removing one remove 42

if you have 39 minutes instead of just removing one minute at a time remove all 39.

this completely eliminates the while statements.