Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you don't want to do it in Excel or as a CVS file as previously mentioned, then I'd go with VB.NET because I think it has built-in support for Excel files. But then I could be wrong because I don't know a whole lot about vb.NET.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean this? I don't know why your program is trying to read 37 files, so I'll just kind of ignore that minor detail and hopefull you can figure out how to do it from the code I am posting below.

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

void display(std::vector< std::vector<int> >& arry)
{
    for(size_t i = 0; i < arry.size(); i++)
    {
        std::vector<int>& cols = arry[i];
        for(size_t j = 0; j < cols.size(); j++)
            std::cout << cols[j] << ' ';
        std::cout << '\n';
    }

}

int main()
{
    std::vector< std::vector<int> > arry;
    for(int who = 1; who < 37; who++)
    {
       std::stringstream str;
       str << "b" << who << ".txt";
       std::ifstream in(str.str());
       if( in.is_open() )
       {
           int nclus, m, n;
           in >> nclus >> m >> n;
           std::vector<int> cols(n, 0);
           for(int i = 0; i < m; i++)
           {
               for(int j = 0; j < n; j++)
               {
                   in >> cols[j];
               }
               arry.push_back(cols);
           }
           in.close();
           in.clear();
       }
    }
    display(arry);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We don't do homework for you. You do the homework, we just help. So post what YOU think are the answers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please post the way you declared those variables. Is input a character array? You generally don't have to do a thing to convert char* to unsigned char*. typecasting is sufficient. And ultoa() takes an unsigned long int as the first parameter, not an unsigned char.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Note that main() always returns int, never ever void.

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

int main()
{
    for(int who = 1; who < 37; who++)
    {
       std::stringstream str;
       str << "b" << who << ".txt";
       ifstream in(str.str());
       // etc. etc.
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Can a standalone programmer design large scale C++ projects?

No because one person doesn't have the time to do it. It takes a team of people to design them so that the project gets the benefits of all their ideas and knowledge. I know Windows Word and the Windows operating system were not designed by just one person but by a large team of people.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It runs but gives me a run time error similar to one I had before
It will depend on where you declared those strings. If you declared them in main() like the code I posted then there should not be a problem. On the otherhand if you declared them in some other function and tried to use them after that function returned then all those strings will have been destroyed and invalidated all those pointers.

As firstPerson mentioned the best practice would be to use a vector of strings in that class and not a pointer so that the class owns the memory of all those strings. That way you won't have to worry about the strings going out of scope.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There were a lot of compiler changes between the two versions that you are using -- 6.0 and 2008. One of the changes is that 2008 uses UNICODE strings by default. You can begin to analyze your problem by turning off UNICODE. Go to menu Project --> Properties (at the bottom of the list), expand Configuration Properties tab, select General. Then on the right side of the screen, third item from the bottom change "Character Set" to "Not Set".

There are several improvements I could suggest to your program, but I suppose you just want it to work for now, so I won't mention them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are right -- all I get is a big white page (IE8 on Win7)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean how compilers turn your source files into object code? Read all about compiler creation. Start by reading a few of these google links.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm confused. You want a std::list of matrices -- each node in the std::list contains a different matrix? Something on this order?

#include <list>

class matrix
{
public:
   matrix(int rows, int cols) 
   {
      data = new int*[rows];
      for(int i = 0; i < rows; i++)
         data[i] = new int[cols];
   }
private:
   int ** data;
};

int main()
{
    std::list<matrix> matrices;
}

>>There is no my matris define. Is there any way to get a value on a matrix in a list exactly like "matx[3][4]"

Using the above code -- the answer is no because the variable matrices in main() is not a 2 dimensional array or list.

If on the otherhand you don't really want that std::list then you can write an overloaded [] operator to do what you want with must the c++ class I posted.

int main()
{
   matrix matrices;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There were no diet sodas.
Gas cost $0.195/gallon

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have this feeling that not having english as my main language makes me miss important points when reading these books.

I look up the new words ofcourse, but still.

Annoying! >:(

English IS my first language and I still look up some words too :) For example, do you know the longest word in the English language? (hint: it has 189,819 letters)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The result is undefined behavior because of the ++ operator. max() evaluates both variables a and b twice, so the ++ operator gets executed twice. Exactly what the final result will be is compiler implementation dependent. Your compiler may produce one value while another compiler may produce something else.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I seem to recall someone telling me Notepad++ will do that too. It's only a text editor so you will have to have a compiler such as MinGW installed too.

In the old days of MS-DOS before IDEs became popular I just used command-line builds and created small batch files to run the compiler + all of its flags so that I didn't have to type them every time I wanted to compile a program. And you can still work like that if you wish. That's a good way to become intimately familiar with how your compiler works.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>sPtr=&s;
Wrong. should be sPtr = s; . But you really don't need that line, or the previous line, at all since both variables are being initialized on line 1 of the code snippet you posted.

This worked for me

#include <string>
#include <iostream>
using namespace std;

class someclass{ 
public:
someclass::someclass(int arraysize, string s[]): numElements(arraysize), sPtr(s)
{
}

friend ostream& operator<<(ostream& out, someclass& c);
private:
string *sPtr;
int numElements;
};

ostream& operator<<(ostream& out, someclass& c)
{
    for(int i = 0; i < c.numElements; i++)
        cout << c.sPtr[i] << '\n';
    return out;
}

int main()
{
string s[4]={"a", "ab", "abc", "abcd"};
someclass c(4,s);
cout << c << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

"new double" is not a variable. "new" is a c++ operator that allocates memory from the heap, and "double" is the type of memory that new will allocate.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@firstPerson -- he doesn't want to use an IDE.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler and operating system?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is no one language to do all that. Writing desktop applications will require different languages and compiler than writing web based applications. And writing mobile applications is still different from either of the other two. First determine what it is that you want to write and then select a language and compiler (if needed) to produce it. There's no "one size fits all" here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>how do I run my .cpp notepad files via the command prompt?
Depends on the compiler you install. There is lots of information about how to create make files for MinGW, which is the MS-Windows port of *nix g++ compiler. Or you can just compile it without a make file. c:> g++ world.c -o world.exe <Enter> The -o flag tells g++ what the final program executable name will be. On *nix they normally do not have extension, but on MS-Windows executable programs normally have *.exe extension.

You may need to set some path environmental variables before you run that command so that MS-Windows knows where g++ program is.

If you use a different compiler, such as vc++ 2010 express, the command line arguments will be completely different.

That's about as simple as I can make it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster


Generally if there's no file such as s.dat, then it creates a file by the name but it it's creating one instead it exits the program. I have to then manually create a file.
Why is it happening so and is there any way that it creates a file automatically if it's not suppose to creating it by itself.

That doesn't make any sense. Are you complaining because it DOES create the file, or that it doesn't. It created the file when I ran your program using vc++ 2010 express, which is just what it is supposed to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

But vector<int> a is a lot smaller than int a[100]; and more efficient if the program only needs something < or > 100.

>>i'm just curious where you get the information from.

I try to use my head for something other than a hat rack. The reason stated above is pretty obvious.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Citation please?

By "efficient" I meant memory wise. And for access speed they can be just as efficient as C style arrays. And where do you find the dimensions hard-coded in a vector?

example

int main()
{
    vector< vector<string> > theList;
    vector<string> row;
    row.push_back("one");
    row.push_back("two");
    theList.push_back(row);
    row.erase(row.begin(),row.end());
    row.push_back("three");
    row.push_back("four");
    theList.push_back(row);

    string s = theList[1][1];
    cout << s << '\n';


}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its a two-dimensional array of strings. Simething like string Rule_Collection[100][2]; except that using vectors is much more efficient because the dimensions are not hard coded.

I've often used the same or similar technique for reading rows and columns (result set) from a database. Where the inner-most vector represents the columns and the outer vector the rows.

>>to the people who already have read chapter 7-4 in this book
Nope, I have not read it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One reason its named "Visual C++" because its a c++ compiler/IDE designed to make writing MS-Windows programs easier. Otherwise it will compile standard c++ programs without a problem unless you try to use something from the newest version of c++ standards which vc++ has not yet implemented. But then most c++ compilers are not 100% c++ standards compliant.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

vc++ 2010 Express. Most IDE's and compilers will compile both C and C++, depending on the file extension is *.c or *.cpp or *.cc. It will also depend on the operating system you are using.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you need to determine where the center of the tree will be, then set an int variable to be that value. The variable count is just the number of stars that will be printed on the current row.

int main()
{
    int center = 10;
    int count = 1;
    for(int i = 0; i < 10; i++)
    {
        printf("%*s", center, " ");
        for(int j = 0; j < count*2; j++)
            printf("*");
        printf("\n");
        --center;
        count++;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Usually, you don't use it, use instead Return 0;

Unless, of course, exit() is used outside main().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The paramarater is the value that the program will return to the operating system so that other programs can use it for some purpose. The value 0 traditionally means the program exits normally without error. Any other value would mean the program encountered some kind of error. The value of the parameter to exit() can be anything you want, its not limited to the three that you posted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where are the code tags???

>>clrscr();
non-standard function that is normally available only to Turbo C. If you are going to post code snippets that everyone might want to use then don't use non-standard functions like that one.

>>cout<<count;
>>cout<<" "<<"+"<<" ";

You can abbreviate that into a single statement: cout << count << " + "; >>getch();
Don't use that in c++ programs. use cin.get() . This is an old thread, but still relevant.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>What made you think that I'll unleash a virus?
I NEVER download executable programs off the internet unless I know that it will be safe for me to use. Did you scan that program with a couple of virus checkers? Viruses can creep in whether you intended to put them there or not.

>>I thought when you copy-paste the colors are lost
Yes, they are lost.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes like any other editor you can copy to clipboard and paste it into MS-Word. -- but why would you want to? MS-Word just screws up the program formatting.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why?? I'm sure it was a lot of fun writing that program, but there are already been several similar programs for a long long time, for example Notepad++.

And I'm not about to download and run that *.exe program. That's one way viruses are spread.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I used Sears & Roebuck catelog for toilet paper when I was a kid growning up on the farm. We didn't have running water in those days.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

esi just contains an address that is within the ds segment. ds is not a pointer -- it contains the address of the data segment. Sometimes you might even see cs:[esi] or even ss:[esi] in which case esi is pointer to somewhere in the code segment or stack segment, respectively.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could use sockets in the MS-Windows program too, so whatever you write for *nix is SORT OF portable to MS-Windows too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Actually for an array with program lifetime
i.e. global variables. And you are right about that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

On MS-Windows the background program(s) would be running as Windows Services. One way to communicate with a service is via COM programming. Of course the serice has to be written as a COM program in order for application programs to talk to it. One common type of service program is a database program. That is a very advanced programming, not for the faint of heart or for beginners. There are several books written about COM programming that will require a lot of studying.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you talking about *nix or MS-Windows?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>mods / featured posters / sponsors /team colleagues etc etc etc are just as prepared to give crap answers as noobs

Yup, I do that on occasion too. Just shows that nobody, even Narue, is above giving crap or wrong answers on occasion. All that my post count means is that I've probably given out a lot more crappy answers than almost anyone else here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to initialize the array to 0 then just declare it like this: int prime[200000] = {0}; and the compiler will most likely use the optimal way to initialize it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Create a small program to test out that function and find out how it works. I don't use that compiler so I can't help you very much. Working with small two or three line programs is a lot easier than trying to work with large programs and DLLs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> On a linux platform you will learn more as you have do all work on your own

Not if you post your questions here on DaniWeb :) There are a lot of expert *nix programmers here ready and willing to answer questions (No, I'm not one of them).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

getch() returns two bytes, not just one, when you press special keys such as arrows and function keys. I like to make the keys negative values so that the program can easily distinguish between special keys and normal keys, but there are other ways such as add 255 to the value return by getch().

int main(int argc, char* argv[])
{
    int c = getch();
    if( c == 0 || c == 224)
        c = -getch();
    
    printf("%d\n", c);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, he could, but that would most likely crash the program because it would be pulling the rug from under that read() function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>please could you help me?

That's like asking "my car is broke -- can you fix it?" A mechanic will need to know a little more details about your car, such as make, model and year.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should be able to learn C and C++ from *nix without any problems -- the language itself is platform independent. You run into cross-platform problems when you start writing programs that call platform-specific functions, such as GUI and hardware. But for learning the language *nix is a good as any other. I suppose it can be a little frustrating when you are just starting to learn what is and is not platform dependent functions.

As for books -- there is an entire thread at the beginning of this c++ forum devoted to that subject.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You may have to post this problem on Microsoft's forum web site. I'm on Windows 7 and have never seen that problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>or show me a 32 bit BGI compiler
There isn't one. AFAIK Borland itself doesn't even support BGI in its current compilers. You will have to upgrade your skills and use something like Code::Blocks or VC++ 2010 Express, both are free.