template<> 37 Junior Poster

Not totaly clear what he is trying to do,
If I understand this correctly, It looks like he is trying to patch something...

template<> 37 Junior Poster

if you know the memory address, you can do stuff like this.

char *p = (char *)0xEF8921;

http://stackoverflow.com/questions/3934775/how-to-initialize-a-pointer-to-a-specific-memory-address-in-c

template<> 37 Junior Poster

Not clear what you mean by different memory address. Perhaps read each dataPY.bar into a different instance of a DataPY class?

template<> 37 Junior Poster

what is the question???? what do you need help with?

template<> 37 Junior Poster

Should be fun, did an editor for debugger before with syntax highlighting etc. Try to design everything in terms of objects, should be good learning experiance. For example create a object model for your editor and implement using classes.

template<> 37 Junior Poster

GOOGLE

http://www.codeguru.com/forum/showthread.php?t=360665

You are probably compiling for multi-byte, is that what you really want?

template<> 37 Junior Poster
template <typename Tdata>

void q1_sort(vector<Tdata> &A, int left, int right)
{
    if((right-left) < ISORT_CUTOFF){ 
        if(data_t == 1)
        {in_sort<Tdata>(A, (int)left, (int)right+1);}   
        else if(data_t == 2)
        {in_sort<Tdata>(A, (int)left, (int)right+1);} 
    }
    else{
    q1_sort<Tdata>(A, left, i-1);
    q1_sort<Tdata>(A, i+1, right);
    }
}
Koinutron commented: Good, quick solution to a problem that was driving me nuts! and I learned good info about template use +3
template<> 37 Junior Poster

This can you you more information than I can:
http://www.cplusplus.com/reference/iostream/istream/

Basically, error checking is a big part of writing programs. If your reading ch by ch, you need to ensure stream is still valid. Stuff can go bad a zillion different ways... at the worst possible time!!!

template<> 37 Junior Poster

I would think a terminal condiion is needed, some way to end it all...

template<> 37 Junior Poster

pseudorandom21 solution is clean and simple, spend some time to understand it

#include <iostream>
#include <string>
#include <sstream>

int main()
{
    std::stringstream strm("it your move");

    std::string token;
    while(strm >> token)
    {
        std::cout << token << std::endl;
    }

    return 0;
}
template<> 37 Junior Poster

In your version you are mixing types, not sure what that will do. For example you are assigning bool to char and comparing char to bool, might want to fix that.

char character;
character=false;

character == false

template<> 37 Junior Poster

An alternate way that might work for you as suggested above...

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
int main()
{
    ifstream istrm;

    istrm.open("proj-8.dat");

    char ch;

    while( istrm.get(ch) )
    {
        if( ch == ' ' )
        {
            cout << ch;
            // strip extra space
            while( istrm.get(ch) && ch == ' ' )
                ;
        }

        if( istrm.good() )
            cout << ch;
    }

    istrm.close();
}
template<> 37 Junior Poster

Might be cleaner if you design you problem in terms of objects (use classes)

template<> 37 Junior Poster

Ask him why when you get a chance, probably has a good reason, although anonymous struct is not part of the c++ standard to the best of my knowledge.

template<> 37 Junior Poster

Also, just out of curiosity, why did you decide to use an anonymous struct below?

struct NodeType //For nodes in a binary expression tree.
{
    TagType tag;
    union //Note that this union type is "anonymous".
    {
        int intValue;
        struct //And this struct type is also anonymous.
        {
            NodeType* left;
            char op;
            NodeType* right;
        };
    };
};
template<> 37 Junior Poster

try this and see what happens, then figure out how it should be fixed

struct node_t
{
    node_t *left;
    node_t *right;
};

void something(node_t *)
{
}

int main()
{
    node_t node;

    something(node*); // #1 what is this??
    something(&node); // #2 pass a pointer to node
}
template<> 37 Junior Poster

do you want to pass eTree * or perhaps &eTree

template<> 37 Junior Poster

What is eTree??

void Expression::display() const
{
    writeNode(eTree*);    //error here
}
template<> 37 Junior Poster

Show the actual error with line number...

template<> 37 Junior Poster

Your signatures are inconsistant. Once you fix there will be other problems...

void writeNode(NodeType* node);
void writeNode(NodeType node)

template<> 37 Junior Poster

can you provide expression.h

http://msdn.microsoft.com/en-us/library/t8xe60cf(VS.80).aspx

template<> 37 Junior Poster

alternatively, you might try using a vector of vectors

vector< vector<int> >

template<> 37 Junior Poster

1. use typedefs to simlify your code
2. use strings rather than char* for key in containers.
3. if you must use char *, custom comparison perdicate must be provided

Below is simple sample

#include <iostream>
#include <string>
#include <map>

int main()
{
    typedef std::map<std::string,std::string> TMap;

    TMap m;
    m["k2"] = "v2";
    m["k3"] = "v3";
    m["k1"] = "v1";

    TMap::iterator iter;
    for(iter=m.begin(); iter != m.end(); ++iter)
    {
        std::cout << "key=" << iter->first << " value=" << iter->second << std::endl;
    }
    return 0;

}
template<> 37 Junior Poster

Try to first think out the logic of the problem without worring about coding it

template<> 37 Junior Poster

If its a cpu scheduler performance is probably important

which implies perhaps a ring-buffer type structure might be useful

Can you describe in more detail what you are trying to do?

template<> 37 Junior Poster

When you hit a space, write it out
then find all sebsequent spaces and throw them away.

WaltP commented: You're kidding. Really? How'd you come up with that? :icon_rolleyes: -3
template<> 37 Junior Poster

You might also want to consider a vector of vectors, which might be easier if your not familiar with pointers


std::vector< std::vector<int> > row;

template<> 37 Junior Poster

What you want is to really understand pointers well, try this article, then go back and see if the above code makes sense

http://www.cplusplus.com/doc/tutorial/pointers/

template<> 37 Junior Poster

Sorry Dude...first read up and understand static arrays before trying dynamic arrays

below seems like a good article

http://www.cplusplus.com/doc/tutorial/arrays/

template<> 37 Junior Poster
int main()
{
    int row = 10;
    int col = 4;

    // col of pointers to rows
    int **dynamicArray =  new int *[col] ;

    // array for each row
    for( int i = 0 ; i < col; i++ )
    {
        dynamicArray[i] = new int[row];
    }

    // initialize with zero
    for( int c=0; c < col; c++ )
    {
        for( int r=0; r < row; r++ )
        {
            dynamicArray[c][r] = 0;
        }
    }

    return 0;
}
template<> 37 Junior Poster
template<> 37 Junior Poster

What platform are you on?

template<> 37 Junior Poster

1. First figure out how to do it by hand
2. Then search google to see how others have solved the problem
3. Finally write your program

http://www.indiastudychannel.com/projects/2080-C-Program-To-calculate-compound-interest-using-CI-P-R-T-P.aspx

template<> 37 Junior Poster

Learn to think and design your programs in terms of real world concepts and use classes to express these ideas.

template<> 37 Junior Poster
std::stringstream out;
    for(size_t i=0; i < size; i++)
    {
        int x = digit[i];
        x = x >> i; // do something to digit
        out << x;
    }
template<> 37 Junior Poster

Perhaps name the object?

class DayOfTheWeek
{
public:
    DayOfTheWeek(const std::string &name_)
    :_name(name_)
    {;}
    const std::string &getName() {return _name;}
private:
    std::string _name;
};

int main()
{
    DayOfTheWeek s("monday");;
}
template<> 37 Junior Poster

GetTickCount() might give you what you want.

http://msdn.microsoft.com/en-us/library/ms724408(v=vs.85).aspx

template<> 37 Junior Poster

Figure out how to end up with two strings, then convert as below. You might try to reassemble the tokens from above or perhaps use std::string substring/replace.

#include <iostream>
#include <stdio.h>
#include <string>

int main()
{
    std::string s1("20010db800000000");
    std::string s2("00000000142857a");

    const int BASE = 16;
    unsigned long l1 = strtoul(s1.c_str(),NULL,BASE);
    unsigned long l2 = strtoul(s2.c_str(),NULL,BASE);

    std::cout << s1 << "=" << std::hex << l1 << std::endl;
    std::cout << s2 << "=" << std::hex << l2 << std::endl;

    return 1;
}
template<> 37 Junior Poster
template<> 37 Junior Poster

It would be good practice to always check your return codes. If you do so, you will most likely find your error.

template<> 37 Junior Poster

Rather than DayOfTheWeek.getDay, use getDay()

Since you are calling a method of the class from withing the class

template<> 37 Junior Poster

You might want to consider to first break the problem into set of points (x,y). Then extract and convert each set of points to numbers.

template<> 37 Junior Poster

Below is one way to break it into token...

#include <sstream>
#include <string>
#include <iostream>

int main()
{
    std::stringstream ipv6("2001:0db8:0000:0000:0000:0000:1428:57a");

    char seperator=':';

    std::string token;
    const size_t MAX_BYTE=8;
    for( size_t i=0; i < MAX_BYTE; i++ )
    {
        std::getline(ipv6,token,seperator);
        std::cout << token << std::endl;
    }
}
template<> 37 Junior Poster

Yikes, is that really Andrew Koenig or a very good Impersonator!!!

template<> 37 Junior Poster

Also, xcode and all their development tools are free

template<> 37 Junior Poster

It may be an entirly different issue but this part of the code has a bug.

The array of zero size is created

Then values are read into the array indexing with i

This index is incremented.

C arrays do not grow dynamically.

Out of bounds access is undefined and cause weird behavior.

#include <iostream>
#include <string>

int main()
{
    int i = 0;
    int sales[i];

    std::cout <<  "sizeof array = " << sizeof(sales) << std::endl;

    std::cout << "Enter a sales amount  (negative to end): ";
    std::cin >> sales[i];
    while( sales[i] >= 0 )
    {
          i++;
          std::cout << "Enter a sales amount  (negative to end): ";
          std::cin >> sales[i];
     }

    return(0);
}
template<> 37 Junior Poster
#include <iostream>
#include <string>
#include <sstream>

int main()
{
    std::stringstream expression(" 3 + 4 ( 5 * 8 ");
    std::string token;

    const char DELIMITER(' ');

    while (std::getline(expression, token, DELIMITER))
    {
        std::cout << token << std::endl;
    }
}
template<> 37 Junior Poster

1. Ofcourse newbies can learn C++!!!
2. Not a game programmer, but I suspect lots of games use c++ since performance is important
3. I use a mac at home, linux/windows at work. You already have everything you need.

a. open a terminal window on your mac
b. type nano (or other editor you know, I use vi since its on every unix system)
c. write your first c++ program:

#include <iostream>

       int main()
       {
            std::cout << "I can do it!!!" << std::endl;
       }

d. build program with g++ compiler: $ g++ -g hello.cpp -o hello

e. run program on bash shell: $ ./hello

f. debug program with gdb debugger: $gdb hello

Now go read up on everything, Enjoy and Have Fun!!!

template<> 37 Junior Poster

Interesing syntax, I thought array initialization has to be a constant???

Is'nt that going to go out of range and cause all kinds of interesing problems?

since i is incremented further down...

int i = 0;
int sales;

template<> 37 Junior Poster

I am able to take the code out of above and compile without any problem.

g++ -g sample.cpp -o sample

Are you able to do that?