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

its better to search there more instead wasting time in reading that stupid doc

Only stupid to those who are too lazy to read and learn from their mistakes.

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

The third parameter is wrong. The parameter is a function pointer to your comparison function

int compare(const void *p1, const void* p2)
{
    // assume the two pointers are really integers
    int* i1 = (int *)p1;
    int* i2 = (int *)p2;
    return *i1 - *i2;

   // This would also work
    return *(int *)p1 - *(int *)p2;
}


...
qsort(statistic, line_num+1, sizeof(TestStatistic), compare);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No, we can't help you because we can't see your program. The warning/error messages give you the line number in your program, all you have to do is go to that line and see the problem.

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

In a class use the new operator to crate a object of the class . Their constructor is used to allocat memory for the data member and fucntion , and distructor is use to free the memory . If we use delete inplace of distructor , will it work ???

The program needs to delete the memory that was previously allocated. Default destructors do not do that, so you need to write your own destructor and delete the memory there. Yes you can delete memory in other parts of the program, but if you do that then set the pointer to NULL so that the delete in the destructor works correctly.

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

I have no clue what all that means.

lancevo3 commented: a great help as usual +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Looks ok to me. What is that nasty error you are getting ?

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

so i'm just sayin... "will the real Tom Gunn, please stand up?"

... And introduce yourself in Community Introductions like every other respectable DaniWeb member has done

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

you need { and } brackets around that else statement. As writen, on dFont++ is part of the else.

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

i think there is some restriction on the output file name length. Any method to remove this restriction?

The restriction is 260 characters, as defined in windows.h MAX_PATH. The problem is in your code.

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

Problem is in the constructor

Deque::Deque(const Deque& oldDeque)
	{
	dArray = new int[oldDeque.dMaxSize];
	for (int i = 0; i < oldDeque.dSize; i++)
		dArray[i] = oldDeque.dArray[i];
	dMaxSize = oldDeque.dMaxSize;
	dSize = oldDeque.dSize;
	dRear = oldDeque.dRear;
    dFront = oldDeque.dFront;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't get the same result with your most recent post

deque 1 is empty
deque 1 (size 0):

deque 1 pushBack()
deque 1 is not empty
deque 1 (size 1): 17

Copy constructor
deque 1 (size 4): 17 2 6 4
deque 2 (size 0):

deque 1 (size 0):
deque 2 (size 0):

Press any key to continue . . .

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

Here is the complete file, just in case I changed something that I forgot to tell you about. Looks like I did change the constructor, but I don't see how that could have corrected anything other than when the parameter to the constructor is 0.

#include "Deque.h"
#include <iostream>
#include <iomanip>

using namespace std;

	Deque::Deque(int MaxSize)
	{
	dMaxSize = MaxSize;
	dArray = new int[dMaxSize];
    memset(dArray,0,dMaxSize * sizeof(int));
	dSize = 0;
	dFront = 0;
	dRear = dMaxSize - (MaxSize > 0);
	}

	Deque::~Deque()
	{
	delete[] dArray;
	}

	Deque::Deque(const Deque& oldDeque)
	{
	dArray = new int[oldDeque.dMaxSize];	
	for (int i = 0; i < oldDeque.dSize; i++)
		dArray[i] = oldDeque.dArray[i];
	dMaxSize = oldDeque.dMaxSize;
	dSize = oldDeque.dSize;
    dFront = oldDeque.dFront;
    dRear = oldDeque.dRear;
	}

	const Deque& Deque::operator=(const Deque& rightOp)
	{
	if(this != &rightOp)
    {
		delete[] dArray;
		dArray = new int[rightOp.dSize];
		for(int i = 0; i < rightOp.dSize; i++)
			dArray[i] = rightOp.dArray[i];
		dSize = rightOp.dSize;
        dFront = rightOp.dFront;
        dRear = rightOp.dRear;
	}
	return *this;
	}

	ostream& operator<<(ostream& osObject, const Deque& rightOp)
	{
	int sub = rightOp.dFront;
	for (int i = 0; i < rightOp.dSize; i++)
		{

		cout << rightOp.dArray[sub] << " ";
		sub = (sub+1) % rightOp.dMaxSize;
   		}
	return osObject;
	}
			
	void Deque::clear()
	{
	dSize = 0;
	dFront = 0;
	dRear = dMaxSize -1;
	}

	int Deque::size() const
	{
	return dSize;
	}

	bool Deque::empty() const	
	{
	if(dSize == 0)
		return true;
	else
		return false;
	}

	bool Deque::full() const
	{
	if(dSize == dMaxSize)
		return true;
	else
		return false;
	}

	int Deque::front() const
	{
	if(dSize == 0) …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

this is what I got

deque 1 is empty
deque 1 (size 0):

deque 1 pushBack()
deque 1 is not empty
deque 1 (size 1): 17

Copy constructor
deque 1 (size 4): 17 2 6 4
deque 2 (size 4): 17 2 6 4

deque 1 (size 0):
deque 2 (size 4): 17 2 6 4

Press any key to continue . . .

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

I only contributed 10% of his rep points -- everyone else apparently thinks he is great too :)

posts:solved ratio doesn't really mean much because it says nothing about who helped solve the problem. I can make a post that says nothing more than "agree", and my solved post count will get bumped when the post is marked solved.

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

You apparently didn't make the changes I suggested

Deque::Deque(const Deque& oldDeque)
	{
	dArray = new int[oldDeque.dMaxSize];	
	for (int i = 0; i < oldDeque.dSize; i++)
		dArray[i] = oldDeque.dArray[i];
	dMaxSize = oldDeque.dMaxSize;
	dSize = oldDeque.dSize;
    dFront = oldDeque.dFront;
    dRear = oldDeque.dRear;
	}

	const Deque& Deque::operator=(const Deque& rightOp)
	{
	if(this != &rightOp)
    {
		delete[] dArray;
		dArray = new int[rightOp.dSize];
		for(int i = 0; i < rightOp.dSize; i++)
			dArray[i] = rightOp.dArray[i];
		dSize = rightOp.dSize;
        dFront = rightOp.dFront;
        dRear = rightOp.dRear; 
	}
	return *this;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am also using Vista. Check the directory in which your program is running and I'll bet my boots that the file is there. If you remove all the commas and dots you will get this filename "testing101213txt"

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

this worked ok for me

int main()
{
    char FirstName[30], LastName[30];
    int Age;
    char FileName[255];
    char filename[255];
     cout << "\nEnter the name of the file you want to create: ";
    cin >> FileName;
    int a=10,b=12,c=13;
    
    
    sprintf(filename, "%s,%i.,%i.,%i.txt", FileName, a,b,c);
cout << "\"" << filename << "\"\n";
    cout << "Enter First Name: ";
    cin >> FirstName;
    cout << "Enter Last Name:  ";
    cin >> LastName;
    cout << "Enter Age:        ";
    cin >> Age;

   
    ofstream Students(filename, ios::out);
    Students << FirstName << "\n" << LastName << "\n" << Age;

    cout << "\n\n";
   
    
    return 0;
}

I presume you are using MS-Windows. If not then possibly your operating system does not support commas and periods embedded in filenames.

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

Well the code I have for the << operator is what was giving to me in class as well. hmmm

There is nothing wrong with the code in that function. The problem is in the constructor but showed its ugly head in the << operator code.

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

What do you mean by that? I thought they got initalized in the default constuctor?

No. The default constructor does not initialize class variables at all. That's why you need to write your own construtors.

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

Look at line 28. Don't you see the difference between the variable name on line 28 and the variable name on line 18 ????:icon_eek: Variable names are case sensitive, meaning filename is not the same as FileName

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

The copy constructor failed to initialize values of dFront and dRear. The program crashes in the overloaded << operator because it uses dFront, which for that object contains some random huge value.

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

It has nothing to do with the age of your compiler. Line 28 is wrong, you are using the wrong variable as the first parameter. That is one good reason to avoid using two variables with the same name except for capitalization.

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

You will have to post the hold thing. The code you posted looks ok to me. Maybe the problem is somewhere else.

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

the last line should be dMaxSize = oldDeque.dMaxSize; and you need to add dSize = oldDeque.dSize; Is the value of oldDeque.dSize > 0 ?

You can delete line 5 because that variable is not used.

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

That's a tall order -- please explain and show what you have done to start solving the program. For example what are the program requirements? I assume (maybe wrongly) what you want to do this as a school assignment. If that is true then what did your teacher say he/she wanted the program to do.

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

This thread is getting too far off-topic. If you all want to discuss this further then please start a new thread in IT Professional Lounge.

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

>>Sure, it might feel harder in the short term, but I think we would reap the benefits eventually

And just what are the benefits of communism? I haven't seen any around the world, such as in China and Cuba. All I see in communist countries is grief, sorrow, and enslaved citizens. Granted that China seems to be turning more to capitalism every year, afterall they practically own the USA now.

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

I think its installed as part of the operating systems. Tutorial here.

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

>>list is supposed to be an array of pointers, so hopefully I declared that correctly.

No, you did not declare it correctly. What you declared was an array of characters. Here is an array of pointers: char *list[LIST_SIZE]; If you want each line of the file to be in the array

string line;
int count = 0;
while( getline(infile, line) )
{
    list[count] = strdup(line.c_str());
    ++count;
}

Since this is c++, not C, it would be even easier to use an array of std::string's or a std::vector

string list[LIST_MAX];
string line;
int count = 0;
while( getline(infile, line) )
{
    list[count] = line;
    ++count;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Only if you buy it.

Why do you bother going to college if you are not going to buy the textbooks? Just how to you expect to learn? Professions don't always tell you everything you need to know in order to complete the assignments, they expect you to read and study too. Yes I know those text books are very expensive, sometimes too expensive. The schools I know about have used books at discounted prices also. You can even check the libraries to see if they have it.

kvprajapati commented: Good advice. +7
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

post the code you tried and the error message(s) because I am unable to see your monitor (I have bad eyes you know).

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

You might want to read this thread -- lots of good info about unicode files and how to read them.

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

That is right. And you can have as many of those as you want.

int main()
{    // start of segment

    if( something )
    {   // start of segment

    } // end of segment

} // end of segment
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AD: *t = _totoupper(*s); I don't know that function, please tell me about it :P

See the link in my post #4

Ohhhh I get it now :) :) Sometimes I'm a little slow at reading sarcastic remarks

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

What compiler and operating system? I always used ODBC for database access and have no idea what SqlDataReader is.

[edit]Nevermind -- that thread was in the wrong forum [/edit]

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

***sigh***

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

but why the result after say yes and no is 0
if say yes everytime is 100 percent

how are you getting an executable program to run with all those compile errors? Most (maybe all) compilers do not produce the *.exe file until all errors are fixed.

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

>>but don't know why its stuck
And what exactly does that mean?

There are a huge number of compiler error messages. Fix them one at a time -- fix an error, recompile, then fix the next error. Keep doing that until you have fixed all the errors and warnings.