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

If you are talking about an int or float array, the answer is no because there is no such value as infinity. Integers have maximum values, which are declared in limits.h header file.

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

lines 41 and 42 are duplicates. delete one of them.

Your program has a number of errors in it -- here is a corrected copy. I changed the indentation of some loops to make it easier for me to see what it's doing -- you can just ignore my style if you wish to keep your own.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable: 4996)

int main()
{
        FILE *infile;
        char line[150];
        int row, col, rows, cols, i;
        double **a, *b, *c;
        double dot_p;
        infile = fopen("matrix5.dat", "r");
        if(infile == NULL){
        printf("Error opening matrix5.dat!");
        exit(0);
        }
        fscanf(infile, "%d %d", &rows, &cols);
        printf("\n_________________________________\n\n");
        printf("There are %d rows and %d columns.\n", rows, cols);
        printf("___________________________________\n\n");
        a = (double **)calloc((size_t)rows, sizeof(double *)); // <<<<<<< HERE
        b = (double *)calloc((size_t)cols, sizeof(double));
        c = (double *)calloc((size_t)cols, sizeof(double));
        for(row=0;row<rows;row++)
        {
          a[row] = (double *)calloc((size_t)cols, sizeof(double));
          if(a[row] == NULL)
          {
                printf("Error creating row %d!", row);
                exit(1);
          }
        }
        printf("a[][]:\n");
        for(row=0;row<rows; row++)
        {
          for(col=0;col<cols;col++)
          {
                fscanf(infile, "%lf", &a[row][col]);  // <<<<<<< HERE
          }
          printf("a[%2d] ", row);
          for(col=0;col<cols;col++) 
              printf("%9.3f", a[row][col]);
          printf("\n");
        }
        printf("\n");
        printf("b[] ");
        //do{
        do{
        for(col=0;col<cols;col++){
          fscanf(infile, "%lf", &b[col]);
          printf("%9.3f", b[col]);
        }
        printf("\n");
        }while(row == rows+2);
        printf("\n");
        for(row=0;row<rows;row++)
        {
          for(i=0,dot_p=0.0;i<cols;i++)
          {
              dot_p += a[row][i] * b[i];
          }
          c[row] = dot_p;
        }
        printf("c[]");
        for(row=0;row<rows;row++)
        {
            printf("%9.3f", c[row]);// <<<<<<< HERE
        }
        printf("\n");
        for(row=0;row<rows;row++)
        {
            free(a[row]); // <<<<<<< HERE
        }
        free(a); // <<<<<<< HERE
        free(b);
        free(c);
        fclose(infile);
        exit(0);

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

you used the wrong index value in this loop

cout<<"enter the elements of the array";
                        for(int i=0; i<y; i++) // <<< this should be < y, not <= y
                        {
                           cin>>bector[i]; // <<<< this one
                        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Maybe you are searching for the wrong thing. Try this one.

sree_ec commented: for showing let me google that for you :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Death of PC? Well, probably in 100 or so years from now after something better has been invented and accepted in business to replace the PC.

Agapelove68 commented: Thank you for the reassurance! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't really matter which one you take first. c++ is an older language but also the most widely used language of the two. You will never go wrong learning both languages.

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

You will want to call FindFirstFile() and FindNextFile() to get a list of all the files and folders, then display the information in a tree control. You can get examples of tree controls from www.codeproject.com, the largest repository of c++ code for MS-Windows on the internet. Once you are on that site just enter "tree control" in its search box.

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

Here is one way to do it. You might want to install VC++ 2010 Express or Code::Blocks instead of using Dev-C++.

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

Yes, your compiler is very very old, written before c++ changed the standards to use headers without the .h extension and before std::

Please post a example inputs that you entered when you ran your program.

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

Ok -- the code I posted will work with that file. This is the test I ran on it

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

using namespace std;

int main()
{

    string line = "123 d45.10 d50.45 d198.56 w45.67";
    char action;
    float value;
    int acctno;
    stringstream s;
    s << line;
    s >> acctno;
    while( s >> action >> value)
    {
        cout << action << " " << value << '\n';
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Another way to do it is to allocate one large block of memory that is x*y*z*sizeof(int) bytes, then calculate the index into it yourself. Freeing up the array is very easy -- since there is only one pointer there will be only one call to free().

int* allocMatrix(int x,int y,int z)
{
    int* ay = (int *)malloc(x*y*z*sizeof(int));
    memset(ay,0,x*y*z*sizeof(int));
    return ay;
}

void disp(int* ay,int x,int y,int z)
{
    int i,j,k;
    for(i = 0; i < x; i++)
    {
        for(j = 0; j < y; j++)
        {
            for(k = 0; k < z; k++)
            {
                int spot = (i*y*z)+(j*z)+k;
                printf("ay[%d][%d][%d] = %d\n",i,j,k,ay[spot]);
            }
        }
    }

}

int main()
{
    int i,j,k,m;
    int x = 5;
    int y = 3;
    int z = 4;
    int* ay = allocMatrix(x,y,z);
    int spot = 0;

    for(i = m = 0; i < x; i++)
    {
        for(j = 0; j < y; j++)
        {
            for(k = 0; k < z; k++)
            {
                int spot = (i*y*z)+(j*z)+k;
                ay[spot] = m++;
            }
        }
    }
    disp(ay,x,y,z);
    free(ay);
}
MarounMaroun commented: Helpful! Thanks Ancient.. always here to help. +1
mitrmkar commented: Effective +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What does the subject of pointers have to do with the subject of data structures? Other than a structure can contain pointers.

Here is an interesting article about pointers written by DaWei

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

How do you think 4/2 is represented in memory? If you use doubles it will be 2.0000... Similarily 4/3 is 1.3333... in memory. Its NOT just a string -- that is the binary representation.

If you want to know how doubles are formatted in memory then you need to study iEEE standards, which is what most PC computers with Intell (or compatible) processors use.

When working with floats and doubles there is no such thing as exact value. Attempting to test for equality will fail in most cases.

jonsca commented: yep +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
struct matrix* InitMatrix(int x, int y, int z)
{
   struct matrix* m = malloc(sizeof(struct matrix));
   // initialize the structures elements

   <snip>
   return m;
}

Free it in reverse orderof allocating it.

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

>>why if I change AllocString(strlen(s), &copy); to AllocString(strlen(s)-7, &copy); I can still get a good result?


AllocString() doesn't actually copy anything into the newly allocate memory but just returns a pointer to it. If you allocate fewer bytes than you try to copy into that memory the outcome will be unpredictable. malloc() will normally allocate more space than what you requested because from a memory management point of view it's just easier and quicket to do that. It will most likely round the amount of memroy up to the nearest 8 or 16 bytes, which guarentees proper alignment for numeric data. But your program can not, or should not, count on that because that behavior can change at any time. For example Microsoft C compilers will add more memory when compiled for debug than for release modes. That's because the compiler might add more code to the program to do runtime buffer overflow checking. Other compilers may or may not act similarily.

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

Here is an article about how to create managed threads in the current version of CLR. When I posted my example earlier today I didn't realize that the OP was using CLR.

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

Here is a simple example. The only reason it includes windows.h is because it uses the win32 api function Sleep() It will become more complicated if each of the threads must access the same global variable or common function. In that cast the threads have to be synchronized to avoid clashes while reading or writing at the same time.

#include <process.h>    /* _beginthread, _endthread */
#include <Windows.h>
#include <iostream>
using std::cout;

void MyThread( void *dummy );


int main()
{
    for(int i = 0; i < 5; i++)
    {
        _beginthread( MyThread, 0, (void *) (&i)  );

        /* Wait one second between loops. */
        Sleep( 1000L );
    }
}

void MyThread( void *param )
{
    int i = *(int *)param;
    cout << "Hello World from " << i << '\n';
}
cwarn23 commented: Great code in speedy time :=]] +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you don't already have MinGW then download codeblocks-10.05mingw-setup.exe

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

you can only put inline executable code in a header file -- mark that function as inline, like you did the other functions.

It is customary to put inline functions inside the class definition, not outside of it.

#include <iostream>

#ifndef EMPLOYEE
#define EMPLOYEE

class Employee
{
 public:
  Employee(long id = 0, string last = "", string first = "",char EmpClass = ' ', double salary = 0) : myId(id), myLastName(last), myFirstName(first),myEmpClass(EmpClass), mySalary(salary) {}

  virtual void display(ostream & out)const
  {
     out << myId << endl << myLastName << ", "
      << myFirstName << endl << myEmpClass << endl
      << "$" << mySalary << endl;
  }
  double getSalary() {return mySalary;}

 private:
  long myId;
  string myLastName,myFirstName;
  char myEmpClass;
  double mySalary;

};




inline ostream & operator<<(ostream & out, const Employee & emp)
{
  emp.display(out);
  return out;
}


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

Continue posting and you will eventually find out what they are. Some members (mods, previous mods, and members who have made monetary contributions) can customize the rank title.

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

>>Get Bloodshed

That compiler hasn't been updated for quite a few years now and uses an old version of MinGW. Code::Blocks is current and still being supported by its writers. Bloodshet isn't.

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

You need to add anothe integer to keep track of the loop counter when the value of biggest is changed so that the program knows which array element contains the largest value. Then you can just simply return return &a[bignum]; where bignum is whatever you want to name the new integer.

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

Set the OFN_NOCHANGEDIR to the Flags item in the OPENFILENAME structure and it will not change the program's current working directory.

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

If you want to hide Form1 while Form2 is up then just set its Visible property to false

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

             Form2^ f2 = gcnew Form2;
             this->Visible = false;
             f2->ShowDialog();
             this->Visible = true;

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

Here you go

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

using namespace std;

int main()
{
    float n;
    vector<float> data;
    ifstream in("float3by3.flt", ios::binary);
    if( in.is_open() )
    {
        while( in.read((char *)&n, sizeof(float)) )
            data.push_back(n);
    }
    // just display the data
    vector<float>::iterator it;
    for(it = data.begin(); it != data.end(); it++)
        cout << *it << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would suspect your program contains memory leaks. win32 api functions do not exhibit that type of problem.

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

Here's a novel idea -- why don't you start with this

#include <stdio.h>

int main()
{
  // put your code here
}
kvprajapati commented: Great starts +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>rec.state == statecontrol

You can not compare two strings like that. All that is comparing is the address of the two character arrays, not their contents. call strcmp() to compare the two.

Also, I suspect you will have big algorithm problems because of the two while loops that both read the same file. Reading should be done only in one spot, not two.

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

That function needs to be prototyped in McCauleyCurrencyConverterHeader.h

adaniel058 commented: Great help and quick reply. Thanks man +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Anyone else dress up for Halloween? If so, then post your pictures here. This is how I looked at my WalMart job today (3 pm - 10 pm)

AndreRet commented: Cool pic... +0
iamthwee commented: 10/10 coolest kid in the playground +0
WASDted commented: nice to see you +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

add << right to the cout statement. I like to split up long lines to make them easier to read without horizontally scrolling the code window. Note that I changed some of the widths you had set, but you can use whatever you want.

If you can you might want to display the column titles using two rows of text instead of one. That will make the columns narrower to fit better on the screen.

cout << setw(11) << left << months[i] << setw(8) << right << avgRain[i] << setw(10) 
              << actRain[i] << setw(8) << total << setw(8) << total2 << endl;
Intrade commented: Absolutely awesome. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You want a code beautifier program.

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

>>PS: is %u Ok for printing out addresses
If you want to see the address in hex instead of decimal use %p

This example will show you how data is stored in memory

#include <iostream>

int main()
{
    int x = 123;
    char buf[sizeof(int)];
    *(int *)buf = x;
    for(int i = 0; i < sizeof(int); i++)
    {
        std::cout << (int)buf[i] << ' ';
    }
    std::cout << '\n';
}
myk45 commented: Thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what is the maximum size length can be?
The maximum value of unsigned int -- see your compiler's limits.h for that value.

If you are reading the text file one line at a time, such as using getline(), then use std::string instead of char* so that you don't have to guess (possibly wrong) about the length of a line.

Jsplinter commented: thank you! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should note that String^ and std::string& are NOT the same thing. You can not mix the two (String is managed c++, std::string is unmanaged c++).

Also, strcpy() will not work with either String^ or std::string without some sort of conversion, such as using std::string's c_str() method.

Since you are writing managed c++ it might be better to change that class to use String^ instead of those character arrays as well as in all the functions.

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

what errors are you getting?

In matrix_add() function you are trying to use an uninitialized pointer m.mat. It has to be allocated memory before setting the array elements in those loops. Move the two lines m.rows = and m.cols = up above the two loops then allocate memory for m.mat.

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

Since you didn't bother to use code tags I'm not going to bother reading it very well. The problem is most likely using calloc() instead of realloc() to increase or decrease the size of the buffer.

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

Of course -- I thought everyone knew how to do that. Just get yourself one of the many free compilers and write the code. As for language -- just take a look at all the languages available in the Software Development menu. Many of them will create a *.exe but some won't because they are interpreted languages.

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

The only time \\ is needed is for string literals, like one you posted because the compiler has to interpret each of the characters in the string literal. When the path is typed in from the keyboard of read from a file the \ does not have to be escaped because the compiler will never see it. So typing the path in an edit control then coping it to a CString object can be done without escape characters.

Jsplinter commented: I see, thank you +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Personnel number (integer greater than 0, enter 0 or a negative value indicates that data entry is over.)

That tells you to create a loop that runs until you enter a value <= 0

int PersonnelNumber = 1;
while( PersonnelNumber > 0)
{
   // do things here

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

VB can not call the methods that take c++ classes as parameters or return values, such as std::string. And VB will have to call the methods by their mangled names as generated by the c++ compiler.

Intrade commented: Succint information to answer the question. Much obliged! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can not use sizeof to get the number of bytes allocated to an array. All sizeof(any pointer here) does is give you the size of a pointer -- on 32-bit compilers it will be 4.

There are two solutions I can think of:
1. Use vector instead of array, such as std::vector<double> ay; You can call vector's size() method to get the number of doubles it contains.

2. Pass the array size as another parameter to the functinon.

n0de commented: Thanks ;) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you blind or just plain stupid?

Unimportant commented: lol 2007 +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes it is possible. A segment is determined by the address in ds register. It has nothing to do with align type. AFAIK segments are never closer than 16 bytes (one paragraph), which is the smallest amount of memory that will be returned by memory allocation function (int 21h, function 48h).

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

After you call EnumWindows() to find the get the window's HWND handle.

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

It would be a lot easier to use std::vector<std::string> instead of that string array, then call std::find instead of your binary search algorithm

Post a few lines from the data file you are using.

EarendurRingern commented: thx :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I finally got this worked out (I'm newbe to Windows Forms).

1. Create Form2 with checkedListBox, or you may already have it on another form. Add this code in Form2.cpp. The form designer doesn't like having loops in the *.h file so I had to put the code in *.cpp file.

#include "StdAfx.h"
#include "Form2.h"

using namespace System::IO;
namespace MyApplication { // Change this to the name of the application
    void Form2::GetMyDrives()
    {
            array<DriveInfo^>^ allDrives = DriveInfo::GetDrives();
            for each(DriveInfo^ d in allDrives)
            {
                this->checkedListBox1->Items->Add(d->Name);
            }
    }
};

2. Call the above function from the InitializeComponent() method in Form2.h, after other initialization for checkListBox1 component.