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

line 5: float vector[];
arrays are declared with the star, like this: float* vector; In the constructor you need to allocate memory for the array vector = new float[x]; Change the name vector to something else because vector is the name of a c++ class declared in <vector> header file.

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

C and C++ languages do not perform garbage collection. That is left up to the programmer.

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

In your example x is an integer while var is a character array. In that case x can not be a pointer to var without a typecast.

Here is a good explaination of pointers.

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

Of course you can learn the basics in a few hours, but it will take years to get really good at it. This is my favorite beginner's tutorial.

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

Don't hold your breath waiting to find the answer for Turbo C. Here is just one of may threads you can find about that topic. Doesn't look good for you.

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

>>while ('q' != getline(cin, str))

getline() doesn't return a character; it returns the this pointer.

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

line 16: variable phone is too small. strncpy() must have enough room for NULL terminator. Must be at least 6 characters, not 5.

Since you are wriing a c++ program why don't you replace C character arrays with std::string? std::string is a lot easier to work with than character arrays, and you can use == operator to compare std::string with char* (string literal).

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

>>int matrixSize(Parser::CircleElems.size());

Same problem I mentioned before -- that is a function prototype. It does not declare matrixSize as a POD int, but as a function.

Is CircleElems vector a non-static member of class Circle? If it is then it can only be accesses via an instance of the Circle class. For example

Circle c;
int matrixSize = c.CircleElements.size();
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

>>int matrixSize(ParserDVG::NodeElems.size());

That looks like a function prototype. You can't put executable code such as .size() there.

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

If its a stack problem as ^^^ suggested you could also just allocate the array double* dblData = malloc(ARRAYSIZE * sizeof(double));

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

Assuming this is an MS-Windows program you could put the settings in the registry, such as HKEY_CURRENT_USER/Software/<Your Program Name Here>. That way your program can get the settings regardless of where the program is on a computer.

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

Example

#include<iostream>
#include <vector>
#include <typeinfo>
#include <limits>
#include <Windows.h>

struct mymem
{
    HGLOBAL hGlbal;
    void* hGlobalPtr;
};

std::vector<mymem> myallocs;

void* MyAllocMem(size_t size)
{
    HGLOBAL hGlobal = GlobalAlloc(GHND, size);
    if( hGlobal == NULL)
    {
        std::bad_alloc e;
        throw(e);
    }
    void* v =  GlobalLock(hGlobal);
    mymem m = {hGlobal,v};
    myallocs.push_back(m);
    return v;
}

void MyFree(void* ptr)
{
    std::vector<mymem>::iterator it = myallocs.begin();
    for(; it != myallocs.end(); it++)
    {
        if( (*it).hGlobalPtr == ptr)
        {
            GlobalFree((*it).hGlbal);
            myallocs.erase(it);
            break;
        }
    }
}

int main()
{
    int* ay;
    try
    {
        ay = (int *)MyAllocMem(ULONG_MAX);
    }
    catch(std::bad_alloc& ba)
    {
        std::cerr << "bad_alloc caught: " << ba.what() << std::endl;
    }
    MyFree(ay);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Which specific fuction are you talking about? win32 api functions normally return 0 if the function failed.

>>is there any other way i can do this in a easier/better manner
Write your own wrapper for the win32 api function that throws an exception, similar to the one that c++ new operator throws. In that case the program would have to use try/catch blocks

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

Output the value of N (which is the i loop counter) before each iteration of the loop in main(). That way when the program crashes due to too big N you will know its value.

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

Hey Perry 31,
I recently was reading up on white space rules for C. From what I gathered, tokens such as variable names, function names, variable data type names, other important words in the language, when in contact with operators are naturally separated.

Because of the phenomenon being true that int *var; is syntactically equivalent to int* var;, int*var;, and int<any number spaces>*<any number spaces>var;,I would suffice it to say that the pointer is considered an operator, which would explain why the organization does not and will never have an effect on the functionality when you, I, or anyone else are programming.

In otherwords, to boil down that long-winded post, the answer is like I said before, There is no difference.

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

Oh, well yes it does. you can use getline() with tab separator, such as getline(infile,name,'\t'); But you still have to fix that structure if you intend to use it for anything.

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

The first thing you need to do is correct that structure -- you only allowed one character for each of those fields, and of course you can't store a name or street address in a single character. Since this is a c++ program you might want to consider using st::string. If you can't do that then expand the fields to use character arrays, such as char Name[80]; so that you can store up to 80 characters in the name.

As for that line in the file, the best approach may be to read the whole line in memory then parse it apart. And that isn't going to be easy due to the way that line is formatted -- spaces within each of the fields.

It might be easier to parse the line backwards (right to left) instead of the normal way from left to right. We see that major is the 7th field from the end, so start at the end and back up to the 7th word. Each word is separated by a space, so just count spaces (assuming the line has just one space between each word.

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

Whether you use Show() or ShowDialog() depends on whether you want a modeless or model dialog window. Below code works for model dialogs. First close Form1 then show Form2. After Form2 is closed you have to show Form1 to make it visible again.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
				 Form2 ^form2 = gcnew Form2();
				Form1->Close();
				form2->ShowDialog();
				Form1->ShowDialog();
		 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't just skip over fields. Read the entire line then extract what you want from it and discard the rest.

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

Didn't your local WalMart sell it on the day of release? Mine did, but I don't know about UK stores.

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

>>is there's anyway to output anything when the computer stops (when it ran's out of stacks )

Nope -- your program is trashed at that point. Post the function you are attempting to write, and tell us the compiler and operting system.

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

what compiler are you using? If you are using a 32-bit compiler then you can use win32 api functions FindFirstFile() and FindNextFile(). google for those functions and you will find example programs how to use them. But if you are using something like Turbo C then there may be no solution for you because that compiler can not use paths and file names that have spaces or are longer than 8.3

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

There is no difference -- just programmer preference.

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

@Perry -- the two loops are still incorrect.

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

>>How i can make a .o file?
Use g++ compiler. The other alternative is to write your own compiler.

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

lines 8 and 9. Why are those loops counting from 0 to 10? Array em only contains 3 trings and array e contains 2 strings.

line 17: array em does not contain a NULL pointer, so line 17 will do nothing.

There are a couple ways to do what you are tring to do. One ways is to add a NULL string at the end of each array so that the program doesn't have to know ahead of time how many strings are in each array. The loops just keep on incrementing until a NULL string is found

The other way is to just hard-code the loop counters with the number of strings in each array, for example for(j = 0; j < 2; j++)

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

>>sizeof(uint16_t) * 16
Wrong. All that gives you is the number of bits (not bytes) in one integer. what you want is the size of one of the arrays, such as ARRAYSIZE*sizeof(uint16_t) >> do i need to use strcpy
No. strcpy() works on strings of text data, not numeric data.

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

You can do this without reg expressions. Note: The code below was not compiled or tested.

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

int main()
{
   char line[255];
   char* ptr;
   FILE* fp = fopen("filename.txt","r");
   while( fgets(fp,line,sizeof(line) != NULL)
   {

      ptr = strstr(line,"<From: ");
      if( ptr != NULL)
      {
          // got it, so now do simething with it.

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

Do you have the VC++ 2005 Professional version? If you have Express then you can forget Gdiplus.dll because it requires MFC as I said in my previous post.

>>2 - I don't understand this one
It means your computer's PATH entironment variable. If you don't know how to change the path, in Windows 7 (maybe Vista too), do this:
Start --> System --> Advanced System Settings --> Environment Variables. That will allow you to change the PATH environment variable. But be careful not to delete anything.

>>3. If you do not have the Pro or better version of the compiler than that will fail and there is no other solution. You are just SOL.

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

sortArray is NOT an array of strings -- see my previous post. Your program passed sortArray[i] which is just one character. char * sortArray = new char[255]; is very similar to char sortArray[255]; in that both are single-dimentional arrays that can only hold a single string of up to 255 characters. What you want is something like char sortArray[255][20]; which holds up to 255 strings of 20 characters each. When you know neither of those dimentions at compile time then you need to declare it with a double star char **sortArray and allocate each dimension as I previously posted.

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

What operating system are you using? TSRs are almost useless with MS-Windows

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

>>And I can't install Visual C++ Express because it requires Windows XP SP3

That's the minimum os. It works great on Windows 7 Home Premium, which I use. What version of MS-Windows are you currently using?

GDI is included in Microsoft Windows SDK which is most likely compatible with all (or most) compilers for MS-Windows operating system.

[edit]Just discovered that the files require MFC, which is not suppported by the Express version of VC++ 2010 nor any non-Microsoft compiler. So this is probably not a library that you can use except to study the source code to find out how to plot charts.

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

>>I am not expert like you. I am learning just less than 1.5months whether you believe or not it is up to you.
I made no mention of that, so that statement is not relevant to the problem or the solution. Sorry that you thought my post was not positive -- I wrote nothing that was ciritial of you. I was just trying to help you improve your program and point out problems. If you can't take the heat then get out of the kitchen because you will always find people who critique your programs. If you can't take that then stop programming and take up basket weaving.


>>you can not put executable code .. are you sure ?
Yes, I am absolutely sure, afterall I've been at this enough to know (about 25 years now). If you split up your program so that it uses two or more *.cpp files and put that header file in each one, then the compiler will complain about duplicate functions. Learn to do it correctly right now so that you do it right when the time comes for you to write more complex programs.

>>i use getch() for freezing the screen to see the result. just way of writing
Yes I know -- but what I said doesn't change that. cin.get() will normally do the same thing but in c++ ways. Both cin.get() and getch() will fail to do what you want if there is already …

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

find() doesn't return 0 if the substring is not found -- it returns std::string::npos, which is defined as -1 (but may be defined as something else by other compilers). In any event, if (!mneumonic.find("END")==1) is wrong. Use this: if (mneumonic.find("END") == string::npos)

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

>>OUTPUT file:

Oh -- you can not view the output file with a text editor such as Notepad because the outpout file is in binary, not ascii. Only your program can read the binary file. If the last few lines of your program outputs the correct value (which is does for me) then there is nothing wrong with your program.

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

>>ifstream inputFile("sic.txt", ios_base::eofbit );

Huh??? I've never seen anyone use eofbit in that context. That might be what's causing the problem. Just use ifstream inputFile("sic.txt"); Change the loop beginning on line 98 to use while(getline(file,line))

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

>>char* anArray[]

That parameter is a 2 dimensional array, what you are trying to pass is a single character.

Now, down in main(), you declared sortArray as a single-dimensional array. That means you can not put more than one string into it. Line 50 will only let you enter a single character, not a whole string.


You need to declare sortArray with two stars, not one, in order to make it a 2 dimensional array of strings char **sortArray= new char* [num]; . Next, inside the loop you have to allocate more memory for the string itself. And the call to sort() must be after the end of the loop, not inside it.

for (int i=0; i<num; i++)
	{
        cout << "\tInput word: ";
        string word;
        cin >> word;
        sortArray[i] = strdup(word.c_str());        
        file << sortArray[i] << endl ;
    }
    insertionSort(num,sortArray);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in square.h -- lines 13-17. You can't put executable code in header files like that. If the intent is to make them inline, then do it like you did on line 9, what is void set_values(int a) {x = a;}; square.cpp: delete conio.h and replace getch() with cin.get(). No point using non-portable C code in a c++ program when its not necessary. It does nothing more than make your code look bad to other people (like your instructor).

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

Post the entire code (or function if its a large program) so we can see what you are doing.

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

Since I can't see your monitor my GUESS is that the *.cpp file is missing one or more header files.

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

Works ok for me. Maybe there is something else wrong with the way your program is reading the file. Try this little program to see if it works with your text file.

#include<iostream>
#include <fstream>
#include<string>
#pragma warning(disable: 4996)

int main()
{
    std::string line;
    std::ifstream in("TextFile1.txt");
    while( getline(in,line) )
        std::cout << line << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can only read bytes, never bits :)

Open the file in binary mode then use file.read() to read into a buffer of 1000 bytes

unsigned char buf[1000];
ifstream in("filename",ios::binary);
in.read(buf,sizeof(buf));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We won't write it for you, but help you with what you don't understand. What exactly don't you understand about the assignment? Have you even made an attempt to write the program? What compiler and operating system are you using?

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

Don't use std in c++ programs as std is the name of a namespace.
You have to repeat the typedef statement in MyProjDlg.cpp

typedef vector<LPTSTR> StudentData;
extern StudentData  stdData;
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.