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

m_pointVar has to be a pointer for that to work. If it isn't, then how to check will depend on the class. Make the class constructor initialize all its variables and the program user won't have to worry about whether it was initialized or not.

Testing for NULL pointer will not even tell you whether the pointer is valid or not. It might be an uninitialized pointer or a pointer that was deleted.

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

This is something similar to what you want -- not exactly but in the ballpark. The button image changes when you hover the mouse over it, so you should be able to change the behavior to make the image stay in place after clicking it.

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

Maybe you should use a check button. Or search these links for something similar to what you are looking for. codeproject.com has a wealth of MFC and other code.

Creator07 commented: You are always the best +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only problem with your program is that you need to set local for the stringstream object.

while (getline(infile, line))
	{
        stringstream strstr(line);
        string word = "";
	    strstr.imbue(locale("german_germany.1252"));
        while (getline(strstr,word, ';')) 
            all_words.push_back(word);
    }

Attached is the output file I got.

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

If you are looking for code that fails, this doesn't work either. for(int x = 1.0; x != 0; x -= 0.1) There are lots of ways to make floats fail due to rounding errors. For example x = 1; x = x / 3; You think the result would be 1/3 right? Wong. Its 0.33333333333 ...

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

Just simply use the macros

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    DWORD dwWord = 1234567890;
    long lWord = LOWORD(dwWord);
    cout << lWord << "\n";
    cin.get();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Start out by reading the Read Me threads at the top of the c++ forum. Especially the FAQ and Books threads.

Then google for c++ tutorials. Best to buy and study books, but if you can't afford them then read tutorials.

>>And my dream is to take over the operating system industry and make every people like my operating system!
LOL. So you want to put Bill Gates out of business???

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

Here is just one of may articles you can find about that topic.


Here are some others.

Salem commented: Works for me :) +36
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

windows is not a compiler -- its an operating system. IMHO vc++ 2008 Express is one of the best compilers/IDEs available today. It produces a lot of errors and warnings that other compilers completly miss. And its debugging facilities can't be beat by any other IDE/compiler on any operating system.

Instead of changing compilers at this point, find out how to increase the warning level so that it will produce better errors and warnings.

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

Probably because you are passing uninitialized variables to functions. If your compiler didn't produce these warnings then use a different compiler.

1>c:\dvlp\test9\test9\main.cpp(59) : warning C4700: uninitialized local variable 'lpcd' used
1>c:\dvlp\test9\test9\app.cpp(16) : warning C4700: uninitialized local variable 'lister' used

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

In function GetCDLists() (main.cpp) you have an object also named GetCDLists. Rename that object to something else, such as GList, or whatever. Just don't give it the same name as the function name.

Then a little later in that function you attempt to call the function with a parameter. That function does not take any parameters.


CDRip::GetVersion: you have to put a return value at the end of that function.

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

There are several ways to fix it.

#include <iostream>
using namespace std;

or

#include <iostream>
using std::cout;
using std::cin;

or

std::cout << "Enter Customer's Name: ";
std::cin.getline(name,15);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

symbolic links are only support in NTFS file systems on W2K systems and newer. Read this article (maybe you have already seen it, I don't know).

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

>>void main();

Remove the semicolon

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

It will also stop at 10 words per line.
I would highly recommend using a vector in this case.

yes, that is a better solution. But, like mine, it doesn't work when there are two or more adjacient semicolons (or some other column separator).

After testing, strtok() doesn't work right either because it also skips adjacent semicolons.

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

The problem you posted in #4 is not the same as the problem you originally posted in #1. Are they the same or two different problems? If different problems then you need to tell us that to avoid confusion.

What different variables do you want? If each column of the csv variable represents a string, then just use an array of strings

string line;
string arry[10];
int i;
while( getline(infile, line) ) // Oos! missed a )
{
      stringstream str(line);
      for(i = 0; i < 10; i++)
           getline(str, arry[i], ';');
}

The above might have problems if there are blank columns where two or more ; in a row, such as "one;;;two" If there are lines like that then it becomes much more complicated and you can't use getline() with that third parmeter.

tux4life commented: Again forgotten a parenthese in the while :P (Also see post #3) +16
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In MFC there are two versions of that function, one global and the other a method of CWnd. The compiler is assuming you want the CWnd version. Just add global scope operator :: like you did with FindWindow() and it will compile correctly.

colmcy1 commented: The man is a legend :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could use getline() with the third parameter

string word;
while( getline(infile, word, ';' )
{
    cout << word << "\n";
}
Nick Evan commented: Too slow, but it's nice to know that great minds think alike ;) +22
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <iostream>
#include <stdlib.h>
using namespace std;


int foo()
{
    cout << " World\n";

    return 1;
}

int main()
{
    onexit(foo);

    cout << "Hello\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Log in as Administrater and you should be able to see the hidden files/directories.

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

Are you logged in with Administrator privileges ?

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

We never talked about infile.clear() in class so I never knew it existed. Thanks everyone.

You need to start reading you textbook :)

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

>>char EVENT_NAME;

That only declares a single character. you need an array, such as char EVENT_NAME[255]; or better yet string EVENT_NAME;

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

It is standard practice to create one or more header files (with *.h extension) then use the #include "MyHeader.h" at the top of each *.cpp file. Projects can have as many *.h and *.cpp files as you want, but only one of them can contain main() function. If you have to share global variables among the *.cpp files then att their declaration to the *.h file with the extern keyword, and declare them again in the *.cpp file without extern.

An example of this might be

// header file
#ifndef MYHEADER_H // code guards
#define MYHEADER_H

int foo(int x, int y); // function prototype

extern int MyGlobal; 
#endif // end of code guards
// cpp file
#include "MyHeader.h"

// globals
int MyGlobal = 0;

int foo(int x, int y)
{
    return x * y;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If I don't have one source file then how to do this? Actually I need that the header files,class,member functions(for process) and main(for application) should be in separate window and I want to execute the program properly.

To add another *.c, *.cpp or *.h file to the project, select the New Item as shown in the first bitmap I attached to this post. That will bring up the screen shown in the second bitmap picture. In that screen just select "Code" and fill in the other stuff.

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

>>Why would this be?
Because after that read operation you have to close the file and clear the errors.

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

>> while ((pos < tope) && (strcmp(NombreBuscado, article[pos].name)!=0))

variable article is not an array. Change article[pos].name)!=0 to article.name)!=0

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

Yes I did mean strtok(), not strchr() :)

I understand what you mean now.

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

You mean like BoundsChecker ?

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

I have not been able to duplicate those warnings with my compiler.

I don't know why strtok() will not work for your program. Here is an example of its use

char iobuf[] = "Hello World";
char *ptr = strchr(iobuf, " ");
while( ptr != NULL)
{
     printf("%s\n", ptr);
     ptr = strchr( NULL, " ");
}

Note that you pass a pointer to a char array the first time, and NULL thereafter.

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

you are getting that seg fault because
line 51: allocate memory to temp
line 52: toss the memory away and reset pointer to somewhere in base_string or NULL
line 65: returns a pointer to the pointer returned by line 52 + the length of char* delim, which could result in an out-of-bounds error. This final pointer can not be free'ed because it doesn't point to the same address that was returned by calloc() or malloc(). So the memory allocated on line 51 is unusable.

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

I gave you my advice and opinions -- take it or leave it, I don't care because its your buggy program not mine.

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

That would be the same code as a set() function. No point coding the same thing twice.

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

When you compile programs with Microsoft compilers in DEBUG mode the compiler will fill pointer addresses with that value 0xcdcdcdcd or some such value like that to indicate that address has not been used. if you code something like this char *ptr = 0; then the address will be 0x0000, as expected, but char* ptr the address is set to 0xcdcdcdcd.

If you are going to test the validity of that pointer, then declare it like this: GridGeneration *finalgrid = 0; or GridGeneration *finalgrid = NULL; , both are equivalent.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
private:
	vector<short>& base_row;      
	vector< vector<short> >& base_mat;   // Where all the elements of matrix are located.

references have to be initialized in the class constructor. I suspect you do not want those to be references, so remove the & reference operator. for (vector<short>::iterator it_1d = base_row.begin(); it_1d<base_row.size(); it_1d++) That is the incorrect way to check for end-of-vector. Test the iterator against base_row.end(), not .size().


There are several other errors, but you should be able to correct those yourself.

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

nanchuangyeyu: One reason for all those errors is because you need using namespace std; before including matrix.h or add it inside matrix.h. In that header file you could also just specify std:: before any STL templates, such as std::vector<std::vector<int>>

nanchuangyeyu commented: generous help,thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the library must be like this:
#include <iostream.h>
all of the library should have a .h or header

I normally don't give negative rep, but I couldn't help myself this time because your post is 100% wrong. Only an ancient compiler would use c++ header files with .h extension.

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

No special name for it -- its name can be almost anything. All it would do is change the value of a variable from one value to something else. And you can code a change method any way you want, or not at all. I normally do not include a change function -- just use the set function to change a value.

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

Here is the function again

char * ustrtok(char *base_string,char *next_str,char *delim)
{
char *str2;
str2=(char*)malloc(100);
if(base_string==NULL && strlen(base_string)<1)
{
next_str=NULL;
return NULL;
}
int len=strlen(base_string);
char *temp;
temp=(char*)malloc(100);

temp=strstr(base_string,delim);
if(temp==NULL)
{
strcpy(next_str,base_string);
next_str[strlen(next_str)]='\0';
return NULL;
}
else
{
int sub_len=temp-base_string;
str2=(char*)malloc(100);
strncpy(str2,base_string,sub_len);
str2[strlen(str2)]='\0';
strcpy(next_str,str2);
return (temp+strlen(delim));
}
}

line 5: That line will cause a crash when base_string is NULL because the second part of that statement will call strlen() with a NULL pointer. Need to use the || operator, not &&.

line 7: that does nothing but set the local copy of the pointer to NULL. When the program returns that pointer disappears, and nothing at all happens to the pointer in the calling function. And even if it did work (which it doesn't) it would cause memory leaks in the calling function. This is one reason I said that pointer needs to be char** instead of char*.

line 14: memory leak because it discards the memory allocated in the previous line.

line 18: unnecessary and can be deleted because the previous line strcpy() will null-terminated the string.

line 24: another memory leak. It was already allocated on line 2.

line 28: another memory leak -- what happens to the memory allocated on line 24???

And in the places where this function is called, I don't see where the memory for that second parameter is ever free()'ed.

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

ustrtok() is broken pretty badly. memory leaks, using uninitialized char pointers, and the second parameter should be char**, not char*

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

That program has a considerable number of errors, bugs, buffer overruns, and memory leaks. I was finally able to get it to read the first file, after correcting all those many problems. (using VC++ 2008 Express on Vista).

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

There have been many major changes to MFC since that compiler was released. I started learning it by doing the Scribble Tutorial

That tutorial will not be useful on VC++ 2005/8 compilers.

colmcy1 commented: Thanks for all the great help, much appreciated +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please attach the file -- not post it. To do that hit the "Go Advanced" butten, scroll down until you see "Manage Attachments" button. That will let you browse your computer file system for the file to upload. Attempting to recreate the file(s) from what you posted can cause a lot of errors.

Salem commented: I admire your perseverance, I gave up caring about this thread a long time ago. +36
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Are you sure the Button is in CMainFrame?

Dialog projects do not have a CMainFrame class (assuming he created a dialog project, not SDI or MDI)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
a = GCD(n1,n2);
	b = GCD(n1,n2);

The values of a and b will be the same because the values of n1 and n2 do not change between the function calls. There is no point in calling GCD() twice with the same parameters.

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

>>In my post#1 every thing described properly.
Then why didn't your program like it?

I don't want to create the file myself, I want to use the one YOU created.

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

i dont know actually how to use gdb.

please u try once from your side to debug and find the solution.

And please teach to about the usage of gdb.

Thanks,
DP

Well why don't you learn how to use gdg? Start with google.

>>please u try once from your side to debug and find the solution.
DaniWeb is not your a debugger.

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

I'm only going to say this once more -- post the file, dummy it up with fake names if you want, but we need your file to work with. The example lines you posted in post #1 don't work

Deepak|23|M
puja|21|f
|XY|

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

When you double click on the button as I showed previously the VC++ 6.0 IDE will create the correct message map entry for you -- you do NOT have to code that yourself. After clicking that button, the message map in the *.cpp file should like something like this:

BEGIN_MESSAGE_MAP(CDlgtestDlg, CDialog)
	//{{AFX_MSG_MAP(CDlgtestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

And in the *.h file

protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CDlgtestDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButton1();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
}

Attached is the complete project I made, minus compiler-generated files.