mitrmkar 1,056 Posting Virtuoso

what do the semi colon and the brackets do?

Those are just printable characters in the output simply for display purposes, i.e. the data of a single telnumber object would display on screen as:

npa: [ value_of_npa_here ]
nxx: [ value_of_nxx_here ]
line: [ value_of_line_here ]

They have no functional impact whatsoever.

mitrmkar 1,056 Posting Virtuoso

everything from about line 163 us what I want to output, but I can't seem to get it to do that.

everything I try is wrong in some way and won't even compile on the individual cpp files...and when hey do compile, I get the same blank lines

You need to devise something like ...

// telnumber
void telnumber::printtostream(ostream& out)
{
    // output npa, nxx and line
    out 
        << "npa: [" << npa << "]\n"
        << "nxx: [" << nxx << "]\n"
        << "line: [" << line << "]\n";
}
// worknumber
void worknumber::printtostream(ostream& out)
{
    // output the base class first ...
    telnumber::printtostream(out);

    // now worknumber data ...
    out << "name: [" << name << "]\n";
}
mitrmkar 1,056 Posting Virtuoso

Now you can tailor those functions so that the output is what you want it to be and in desired order. I.e. on a per-class basis decide what you want to output.

mitrmkar 1,056 Posting Virtuoso

I can't for the life of me figure out the implementation of those virtuals though, nothing I put in outputs anything from main except 172, 173, 177, 181, and 185. I need to figure out how to make it see the other lines as "inputs" to those functions and I don't know how to do that

Maybe the following helps ...

// telnumber
void telnumber::printtostream(ostream& out)
{
    out << "telnumber\n";
}

// worknumber
void worknumber::printtostream(ostream& out)
{
    telnumber::printtostream(out);
    out << "worknumber\n";
}

// billnumber
void billnumber::printtostream(ostream& out)
{
    worknumber::printtostream(out);
    out << "billnumber\n";
}
mitrmkar 1,056 Posting Virtuoso

/*first error checking!*/
if (row>ROWS || row < 0 || seat>SEATS || seat <0)
return 1; //error!

what are this for????

Well, it is a check for valid ranges with regard to the array. You must not access any array out of bounds. Actually there is a slight error, it should be

if (row >= ROWS || row < 0 || seat >= SEATS || seat <0) 
{
     // improper value (out of bounds) for either row or seat
     // return a value that signifies an error ...
     return 1; //error!
}

E.g. if you have an array of size 5, the last valid index is four (4) not five, this is because array indexes start from zero. So, the following would be wrong

const int ARRAY_SIZE = 5;
int int_array[ARRAY_SIZE];

int_array[ARRAY_SIZE] = 123; // Wrong
int_array[ARRAY_SIZE - 1] = 123; // Right - sets the last int in the array to 123

Naturally array indexes are always non-negative, hence the check for e.g. row < 0 .

mitrmkar 1,056 Posting Virtuoso

when i input rows and column....

the print result are all X...

I gave it a try and there is one 'X' rest being '*'.

// output was
after userinput

                 Airplane Seat Assignment
******
*[B]X[/B]****
******
******
******
******
******
******
******
******
******
******
******

I.e. the expexted result. Are you sure you did not have that 'X' there?

mitrmkar 1,056 Posting Virtuoso

You should (really) check the return value of WaitForSingleObject() and react accordingly. And also understand what it means to use zero as the time-out interval with WaitForSingleObject().

mitrmkar 1,056 Posting Virtuoso

Two simple examples, hopefully you'll get something figured out of those ...

class a
{
public:
    a(string s1, string s2){}
};
class b : public a
{
public:
    // default ctor
    b() : a("", "") {}

    // ctor with 4 strings
    b(string as1, string as2, string bs1, string bs2) : a(as1, as2) {}

    // ctor with 4 strings plus an int
    b(string as1, string as2, string bs1, string bs2, int bint) : a(as1, as2) {}
};
int main()
{
    b b1("asdf", "asdf", "asdf", "asdf");
    b b2("asdf", "asdf", "asdf", "asdf", 123);

    return 0;
}

The above changed so, that the 5 arg ctor has a default value for the integer argument, that way the 4 arg ctor can be dropped altogether ...

class a
{
public:
    a(string s1, string s2){}
};
class b : public a
{
public:
    // default ctor
    b() : a("", "") {}

    // ctor with 4 strings plus an int with default value zero
    b(string as1, string as2, string bs1, string bs2, int bint = 0) : a(as1, as2) {}
};
int main()
{
    b b1("asdf", "asdf", "asdf", "asdf");  // this one uses the default value
    b b2("asdf", "asdf", "asdf", "asdf", 123);

    return 0;
}
henpecked1 commented: very helpful without doing it for me +1
mitrmkar 1,056 Posting Virtuoso

When you post code, please use code tags ...
http://www.daniweb.com/forums/announcement8-3.html

mitrmkar 1,056 Posting Virtuoso

anytime when I call a function, it says that the function being called does not take 0 parameters? What does this mean?

It means that you simply need to supply one or more parameters to the function, depending on how that functions defined.

// you must pass one integer to this function
void function1(int xyz); 

// you can call this one without a parameter, 
// in which case xyz will be zero
void function2(int xyz = 0);
mitrmkar 1,056 Posting Virtuoso

Initialize outside the class i.e.

// outside your class ...
const HANDLE MultiReader::hReaderMutex = CreateMutex( NULL, TRUE, "ReaderMutex");
Cybulski commented: Thanks for these tips! +1
mitrmkar 1,056 Posting Virtuoso

hReaderMutex is not defined anywhere, hence the error. To get over this problem you need something like ...

// in MultiReader.cpp ...
const HANDLE MultiReader::hReaderMutex = CreateMutex( NULL, TRUE, "ReaderMutex");

However, this is a bit bad construct, because when the CreateMutex() fails, you will not know the reason for the failure (GetLastError()).

mitrmkar 1,056 Posting Virtuoso

Now parameter 4: it should be &adress of this string, amirite?

Basically a pointer (cast to void *) to anything you want the thread routine to receive via p_pVoid argument.

mitrmkar 1,056 Posting Virtuoso

The poor problem is that neither printf nor cout of M$ visual c++ is able to print out long double values!

Surprisingly, at some point M$ dropped support for 80 bit long double, nowadays long double and double are equivalent (64 bits) (although distinct types).

mitrmkar 1,056 Posting Virtuoso

The one in Dev-C++. (not sure what its called)

Well I take that you use the Dev-C++ IDE, so add the files to your project (create a new project, if you don't have one). Adding an existing file to project is done via Project/Add to Project menu. Once you have all required files you can build the project.

Here are some basic instructions ...
http://csjava.occ.cccd.edu/~gilberts/devcpp5/

mitrmkar 1,056 Posting Virtuoso

I have two basic questions.
1) Why can I not include fstream and/or string headers in my gui project?
2) Why can I not instantiate variables outside of the WindowProcedure or the WinMain functions?

#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include "my.cpp"

// since fstream and string are in the 'std' namespace 
// use the following ...
using namespace std;
// or otherwise you'll have to specify 'std' explicitly, i.e.
std::string astring = "something";
std::ifstream somestream;

// a global variable, the wrong way ...
int someint;
someint=3;//error: expected constructor, destructor ...
// another global variable, they have to be initialized at once ...
int someotherint = 123;

If you #include "my.cpp" then you must not compile and link the "my.cpp" along with the project, or your linker will complain about multiple definitions. I think you should change that so that you write a respective header file and include it instead of "my.cpp" i.e. you'd have #include "my.h" .

So all in all, the errors are not related to a GUI program in any way.

mitrmkar 1,056 Posting Virtuoso

How exactly I can introduce "phere" in my code? I tried the "#include getch.h" but it won't help me at all

I assume that in some file you have for example something like

// struct or class named prs
struct prs
{
    // something here
};
// a function which takes a pointer to prs
void edit_rec (prs * p);

maybe 'phere' appears also there, so you might post that file (at least).

mitrmkar 1,056 Posting Virtuoso

Im using visual studio 2005 on XP and am recieving an error in my program that looks as if the call is not matching what is in my lib. I have been doing some reading about the code generation phase of the compiler and find that I should look at the "code generation phase" of the compiler". The problem is that I have no idea what that is and how to do it. Can anyone help?

Might be much more useful to post the relevant code and the error that you are receiving.

mitrmkar 1,056 Posting Virtuoso
int myfunction(int argc, char *argv[]){
int i;
  	for(i=0;i<argc;i++)
    	unlink(argv[i]);
}
int main(){

int argc; // argc is not initialized to any value, what might be its value here ??
char **argv; // argv is not initialized to any value, what might be its value here ??

// Now you call myfunction() with random data, expect most anything ...
myfunction(argc,argv);

}
Salem commented: Quite so. +17
mitrmkar 1,056 Posting Virtuoso

Thank you for reply... but my question is different.. my pointer is void pointer(void *) and it may be RAW data..it could be anything. but sure tht it is not string. waiting 4 reply..

Like Edward already showed, you need to know the size of the memory block to copy, then use malloc() to allocate a buffer large enough, and finally use memcpy() to copy the data to the allocated buffer.

mitrmkar 1,056 Posting Virtuoso

Regarding code readability, you could save a lot vertical space by changing

cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";
	cout << "\n";

to

cout << "\n\n\n\n\n\n\n\n\n";
mitrmkar 1,056 Posting Virtuoso

the code is updated i just need my question answered, anyone?

Assuming that "the game just shuts down" still is the question, it is best if you post the updated code, so it can be given a test ride.

mitrmkar 1,056 Posting Virtuoso

The problem is that The read file is written completely into file.

The code seems to try to do just that, i.e. as long as data is successfully read, write the data. Maybe you need to add some code that breaks the loop based on some condition?

Or did you perhaps intend to say:

The problem is that The read file is NOT written completely into file.

mitrmkar 1,056 Posting Virtuoso

Yeah, Thats exactly what I want, but how do you link the object files together to make a single executable program? And when I tried making the two files, and putting the code on to them, it didn't work.

Thanx

What compiler are you using?

mitrmkar 1,056 Posting Virtuoso

In the .cpp file I have declared a object to the class as: CSafePtr<int> myobject(int* t);

The compiler actually sees that as a function prototype, i.e. a function named myobject, taking an int pointer and returning CSafePtr<int>.
So, you'd need to change it as stephen84s already pointed out.
However, CSafePtr will not work with native types, since it issues calls to AddRef() and Release(). So you need to have classes/structs implementing those.

mitrmkar 1,056 Posting Virtuoso

well i was trying to get the buffer or text in the Input box and then when the button Submit is pressed it displays it into the Output window.

Maybe you can devise something out of the following ...

switch(wParam)
{
	...

	case IDC_Submit:
	{
		#define MAXTEXT 1024
		char text[MAXTEXT] = {0};		  

		// try getting the needed window handles
		HWND input	= GetDlgItem(hWndDlg,IDC_Input);
		HWND edit	= GetDlgItem(hWndDlg,IDC_Window);

		if(input && edit)
		{
			// try getting the text of the IDC_Input control
			if(GetWindowText(input, text, MAXTEXT))
			{
				// try setting the text of the 
                                // IDC_Window control
				if(FALSE == SetWindowText(edit,text))
				{
					// error
				}
			}
			else
			{
				// error or no text avail
			}
		}
		else
		{
			// error
		}
	}		
	return TRUE;		
}
break;
mitrmkar 1,056 Posting Virtuoso

I have to ask you, what is the following line supposed to do? HWND inputB = GetDlgItem(hWndDlg,(GetWindowText(input,NULL,NULL))); The following will not work, 'inputB' is a window handle, not a pointer to a char array. SetWindowText(edit,(const char *)inputB); You need ...

char text[SOME_SIZE] = {0};
// ... code that sets the content of text[] ...
// try setting the edit control's text
if(FALSE == SetWindowText(edit, text))
{
    // error ...
}
mitrmkar 1,056 Posting Virtuoso

A major change is required there, you cannot do it with one for() loop, first you have to initialize the array before doing any searches

// initialize the whole array first
for ( int i = 0; i < arraySize; i++ )
{
    myarray[i]= 1 + rand() % 200;  // [B]range 1 .. 200[/B]
}

// then issue [B]100[/B] searches ...
for ( int i = 0; i < [B]100[/B];  i+ )
{
   Key= 1 + rand() % 200; // [B]range 1 .. 200[/B]
    int element = Search(myarray,Key, arraySize);
    ...
}
mitrmkar 1,056 Posting Virtuoso

Have you tried Vintage Computer Forums?
http://www.vintage-computer.com/vcforum/index.php

mitrmkar 1,056 Posting Virtuoso

I have a string of the form "abcd\"1234\"efgh". I want to extract 1234 from this string. How should I do this?

You might use strtok(), see
http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

mitrmkar 1,056 Posting Virtuoso

Is this simply an installation problem?

Sounds like one, try adding the Dev C++ .\bin folder into your PATH and see if that makes any difference. Might be that the Dev C++ installer does not comply with Vista leaving some things missing.

mitrmkar 1,056 Posting Virtuoso

but 'mkdir' is pure linux

Nope, Windows recognizes mkdir as well ;)

mitrmkar 1,056 Posting Virtuoso

I m not getting..it..

some more info or example code plz...

Since you appear to be on Windows, one way is to use GetFileAttributes(), see
http://msdn.microsoft.com/en-us/library/aa364944.aspx

mitrmkar 1,056 Posting Virtuoso
HANDLE clip;
        
    if (OpenClipboard(NULL)) {
      clip = GetClipboardData(CF_TEXT);
      CloseClipboard();
    }

    < snip >

That was not what I meant to say, below is a basic scheme for doing the intended clipboard operation ... it adds the step of locking/unlocking the respective global memory block

if (OpenClipboard(NULL)) 
{
	// Try grabbing a handle to the non-UNICODE text data
	const HANDLE hglb = GetClipboardData(CF_TEXT); 

	if (hglb != NULL) 
	{ 
		// Try locking the memory block getting a pointer 
		// to the start of the data

		const char * lptstr = (const char *) GlobalLock(hglb);

		if (lptstr != NULL) 
		{ 
			// got it, however, don't make any assumptions 
			// like the data being NULL-terminated and such ...

			// here you can utilize the lptstr pointer ...

			// done, unlock the memory block ...
			GlobalUnlock(hglb); 
		} 
	} 

	// All done with the clipboard operations, close it
	CloseClipboard();
}

Related samples here
http://msdn.microsoft.com/en-us/library/ms649016(VS.85).aspx

mitrmkar 1,056 Posting Virtuoso

A note regarding clipboard usage, whenever you successfully open the clipboard, don't forget to close it by calling CloseClipboard() when you're done with the clipboard operations.

Nick Evan commented: yup +6
mitrmkar 1,056 Posting Virtuoso

I just want to know how the code should be modified to get decreasing order. Please help me.

You need to study the impact of if( a[i] > a[j] ) statement.

With regard to the merge sort code you posted, if you can compile it without errors, then get yourself another compiler. Otherwise, you can get a fresh compilable copy of it from ...
http://linux.wku.edu/~lamonml/algor/sort/merge.html

mitrmkar 1,056 Posting Virtuoso

Use cin ..

float f;
// input one value
cin >> f;  // then .. push_back(f)
int i;
// input one value
cin >> i; // then .. push_back(i)
mitrmkar 1,056 Posting Virtuoso

Ok, one more question if you don't mind helping me out. I would like to make it so that if the line is less than 79 characters long, it will check the next line to see if the first word will fit on the current line without passing the 79 character limit.

Remember the length of the line stored in 'file'. Then, when you read in a line, lookup the first space in the input, so you get the length of the first word and if the length is small enough, replace the last newline with a space and append the word + newline to 'file'. Of course, you could make it work so that multiple words will be appended to the last line.

mitrmkar 1,056 Posting Virtuoso

Thanks but the errors are still same. Even though the semicolon is missing from the prevous.. The most errors came from "unknown characters"

Well, given the code you've posted this far, makes it impossible to figure out further what goes wrong ... for one example, what is 'phere'? Is it something that you have in "getch.h"?

mitrmkar 1,056 Posting Virtuoso

There are actually a couple of semicolons missing from Joshmo's correction, for starters you might change both if (!p) exit(-1) to if (!p) exit(-1) [B];[/B] and then recompile and post the new errors. Most probably you are receiving most of the errors due to the "/var2/local/include/getch.h", so you might post that file also. (I take that e.g. 'phere' and other related things are declared there(?))

mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

The problem probably lies in how you use indexes. Note that array indexes are zero-based i.e. if you have an array holding 5 elements, the last valid index is 4, not 5. Consider

const char *article[ 5 ] = {"the", "a", "one", "some", "any" }; 
int i;
// print all 5 strings .. valid indexes are 0 .. 4
for(i = 0; i < 5; ++i)
{
    printf("%d=%s\n", i, article[ i ]);
}

With this regard you need to revise your code.

mitrmkar 1,056 Posting Virtuoso

Shouldn't you by now be familiar with code tags??
http://www.daniweb.com/forums/misc-explaincode.html

mitrmkar 1,056 Posting Virtuoso

A couple of things, get rid of the eof() in the while() loop, instead use

int format_file(string filename)
{
    ...
    while (getline(readfile, line))
    {
    ...
    }
}

If 'line' contains only whitespace, then the following will crash because line.length()-1 will be negative

//check for trailing spaces
 while (line.substr(line.length()-1) == " ")
       line.erase(line.length()-1);

You don't have to use substr() to check for individual characters, better way is

if(line[ valid_index_here ] == ' ')
...
mitrmkar 1,056 Posting Virtuoso

You might post the relevant parts of the code, otherwise there is no way to help much more.

mitrmkar 1,056 Posting Virtuoso

Sorry, I forgot to mention about the argv. Argv[0] is originally the program name, but after dealing with flags, the program does some magic (that I haven't really tried to figure out because it doesn't really affect the outcome) that ends up with argv[0] as the url.

The original program modified the argv strings. I'm trying to use another variable and failing.

How about getting rid of the original magic altogether? So you'd have untouched argv[] and simply hard-coded opt_httphost = "the hard-coded address"; .

mitrmkar 1,056 Posting Virtuoso

The memory that argv[0] points to is not writable.

I want to hard code the address in the program.

Why don't you just do something like

opt_httphost = "the hard-coded address";
mitrmkar 1,056 Posting Virtuoso

Thank u very much for this,

Why we are putting getchar() again
If it is not what happening there
please give me reason

Let's say you type in one letter 'a' and press Enter, at that point, in the input buffer are two characters, the letter 'a' plus the newline character '\n'.
Now your program reads the letter 'a' and removes it from the input buffer. But, the newline character '\n' is still there waiting to be processed and your while() loop automatically reads the '\n' - hence your program prints "you enter wrong choice" when you don't expect it to do that.

So, you must somehow handle the '\n'. You can either remove it by means of extra getchar() call(s) like already shown above, or you could add a case to your switch, i.e.

main()
{
  int grade;
  int acount =0;
  int bcount =0;
 while((grade=getchar())!=EOF)
 {
     switch(grade)
    {
 [B]       case 'n': [/B]
             // the newline, do nothing here, just break ...
             break;
        case 'a': ++acount; break;
        case 'b': ++bcount; break;
        default:   printf("you enter wrong choice"); 
    }
  }
return 0;
}

Edit: Oh well, didn't see Aia's post ...

mitrmkar 1,056 Posting Virtuoso

About the if/else usage

if( array[j]==key){
        search=search + 1;
        success= success + 1;
    }
    else if(array[j] !=key){
        search=search + 1;
        success=success;
    }

You can change it to

if( array[j]==key){
        search=search + 1;
        success= success + 1;
    }
    else{ // here you already know that array[j] != key
        search=search + 1;
        success=success;  // <- that has no effect, you could remove it
    }

Then, in general you should format the code properly, as of now it's difficult to read, consider keeping related things together and properly indented

for( ... )
{
   for( ... )
   {
      if( ... )
      {
      }
      else
      {
      }
   }
}
mitrmkar 1,056 Posting Virtuoso

Check in the generated msado15.tlh if it contains the ADODB namespace.
i.e. see can you find the following in it

#include <comdef.h>

namespace ADODB {
...

I guess it does, in which case you can use either

using namespace ADODB;

// or

ADODB::_ConnectionPtr m_pConn;

Which compiler are you using?