mitrmkar 1,056 Posting Virtuoso

At least one semicolon seems to be missing ...

int threedice::getsumFaces()
{
         return die1.getroll()+die2.getroll()+die3.getroll() [B];[/B] 
}
mitrmkar 1,056 Posting Virtuoso

I am still leaking memory =[

The _itoa_s() did not actually have much to do with the memory leaking, it was just a safety measure so that your program will not crash.

About the memory leaks, I think there's at least two places where it happens

1) For each SetTimer() call there should to be counterpart KillTimer() to use the timer resources properly.
2) You are not calling ReleaseDC(hwnd, hdc) in your WM_ERASEBKGND handler, i.e. every hdc you get using GetDC() is to be released by ReleaseDC(hwnd, hdc).

mitrmkar 1,056 Posting Virtuoso

Because of the way how you use _itoa_s(...) and the related buffers, _score, _tempscore and val, the program runs currently on good luck.
You could change all the _itoa_s() calls to use a single array of chars of sufficient size,
i.e.

static char itoa_conv_buff[MAX_BUF_LEN_HERE];
_itoa_s(num, itoa_conv_buff, MAX_BUF_LEN_HERE, 10);
mitrmkar 1,056 Posting Virtuoso
if(packe[q].strinput[0] == ' ') 
{
    q++;
    // Because you have incremented q by one,
    // the fprintf() call below is guaranteed to produce
    // unwanted output ...
}

// You must change your code so that you know whether to use 
// packe[q].strinput or packe[q - 1].strinput ...
fprintf(creafile, "%d %s \n", timeslot1[i],  packe[q].strinput);
mitrmkar 1,056 Posting Virtuoso

You are trying to use a string "\0" there, instead you have to use '\0', i.e.

if (x==strlen(a))
    current[x+1] = '\0';

and be careful not to access indexes that are out of bounds.

mitrmkar 1,056 Posting Virtuoso

You might also make use of the strstr() function
http://www.cplusplus.com/reference/clibrary/cstring/strstr.html

mitrmkar 1,056 Posting Virtuoso
if( one == 'o' && two == 'l' && three == 'l' && four == 'e' && five == 'h' )
{
    
    // Select only as many characters as in string 'hello'
    //  i.e. [B]five[/B] ...
    this->richTextBox1->Select((positionen - 5), [B]5[/B]);

    this->richTextBox1->SelectionColor = Color::Red;
    MessageBox::Show(this->richTextBox1->SelectedText);
}
mitrmkar 1,056 Posting Virtuoso

Strange if it does not compile,
maybe you have added the handler in a 'wrong' way.

To add the handler for the KeyUp event,
1) Select the textbox control on your form
2) right-click and select Properties
3) double-click on the row which reads "KeyUp"
=> the editor creates the handler for you
4) type in the code and compile

mitrmkar 1,056 Posting Virtuoso

Am I on the right track or have I missed something.

You have now missed something, you are trying to access the KeyCode in wrong handler (TextChanged).

Instead, for e.g. the KeyUp event, use ...

private: System::Void textBox1_KeyUp(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e)
{
	if(Keys::C == e->KeyCode)
	{
              // Do something here ...
	}
}
mitrmkar 1,056 Posting Virtuoso

Just pointing out the fact that in C/C++, array indexes are zero-based.
A simple example

#define NUM_ELEMENTS 3
int Quantity[NUM_ELEMENTS];  // An array of three integers

// Assign a value to each element
Quantity[0] = 123;
Quantity[1] = 456;
Quantity[2] = 789;

// Now, to output all elements, last valid index is 
// (NUM_ELEMENTS - 1) instead of NUM_ELEMENTS, so ..
for(int nn = 0; nn [B]<[/B] NUM_ELEMENTS; ++nn)
{
     cout << "value at[" << nn << "] = " << Quantity[nn] << "\n";
}
mitrmkar 1,056 Posting Virtuoso

Could it be that you have not escaped backslashes in your string?
I.e. in your code the string should be:

const char regex[] = "^\\[\\d{4}\\-\\d{2}\\-\\d{2}\\s\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3}\\]\\s\\w*\\s*\\w*\\.+\\w*\\:\\d{4}\\sHello"
mitrmkar 1,056 Posting Virtuoso

Could you post the code that wraps CreateProcess?

mitrmkar 1,056 Posting Virtuoso

I'm not sure whether I fully understood your question, but
consider the following program

#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
	if(2 == argc)
	{
		cout << "received: (" << argv[1] << ")" << endl;
	}

	return 0;
}

Let's say that the program executable is named arg1.exe, and you invoke it as follows:

arg1.exe "this string contains spaces"

you should see the following output:

received: (this string contains spaces)

mitrmkar 1,056 Posting Virtuoso

Try valgrind
http://valgrind.org/info/

As a general note, you should add error checking to your code. As of now, there is none.

mitrmkar 1,056 Posting Virtuoso

The bahaviour would perhaps be more understandable if written like

int main()
{
   using namespace std;
   for (int i = 0; i < 3; i++)
   {
       for (int j = 0; j < 3; j++)
       {
           cout << i << " " << j << endl;
       }
    }
   return 0;
}
mitrmkar 1,056 Posting Virtuoso

Appears as if you were not having the corresponding .cpp included in scope of compile/link, i.e. the one in which you've implemented e.g. AppointmentBook::AppointmentBook() ...

mitrmkar 1,056 Posting Virtuoso

You need to reset the file's error state flags, see e.g.
http://www.cplusplus.com/reference/iostream/ios/clear.html

[B]     file.clear();[/B]
     file.seekg(ios::beg);
     while( file >> word)
         cout << word;
mitrmkar 1,056 Posting Virtuoso

Then you could loop through the array and convert the ints one by one using something like

char_array[index] = int_array[index] + '0';

In general, to convert any integer value to a std::string, you can use a stringstream:

stringstream sstream;
	string astring;
	int value = 213123;
	sstream << value;
	sstream >> astring;
mitrmkar 1,056 Posting Virtuoso

About the punchmeinthehead() function ...

void punchmeinthehead()
{
	const int maxin = 16;
        // Here you have three uninitialized arrays of char, use a 
        // debugger to see what they contain here ...
        // (Shouldn't you instead be using the variables 
        //  that you have in your main() ?)
	char lastName[maxin] ;
	char firstName[maxin] ; 
	char midName[maxin] ;
	
        // if your three arrays are OK at this point, the following works
	size_t length = strlen(lastName) + strlen(firstName) + strlen(midName) + 1;

	char  *fullName = new char[length];
        // fullname may also be NULL at this point
	<snip>
        // Did you account for the extra space character when 
        //  allocating memory?
	strcat (fullName, " ");
	<snip>
}

Hmm .. you could rename punchmeinthehead() to punchmeintheheap() ...

mitrmkar 1,056 Posting Virtuoso

A link that D. Sinkula earlierly posted in this thread,
http://www.di-mgt.com.au/cryptopad.html
maybe it went unnoticed by you ...

mitrmkar 1,056 Posting Virtuoso

Anyone interested in various ways of calculating factorials should look into
http://www.luschny.de/math/factorial/FastFactorialFunctions.htm

mitrmkar 1,056 Posting Virtuoso

That will not work out-of-the-box, you should take a look at:
stringize and the token-pasting operators
e.g. here
http://www.keil.com/support/man/docs/c166/c166_pp_tokenpastingop.htm

mitrmkar 1,056 Posting Virtuoso

i can't run this their is plenty of errors coz using namestd; is not available in My turbo C

Just grab yourself an up-to-date, free development environment,
for example
http://www.codeblocks.org/
or
http://www.bloodshed.net/index.html
or pick one from ...
http://www.bloodshed.net/compilers/index.html

mitrmkar 1,056 Posting Virtuoso

You should also handle factorial of zero i.e. 0!

mitrmkar 1,056 Posting Virtuoso

This

if(buffer[posinstream] == " " || buffer[posinstream] == "_")

should be

if(buffer[posinstream] == ' ' || buffer[posinstream] == '_')
mitrmkar 1,056 Posting Virtuoso

A minor note .. why are you skipping the ReadInGroup[] at index 0?
In your for loop, you start at index 1 instead of 0, so that leaves the first
index of ReadInGroup[] unprocessed.
Is that what you want, or should you change

for (int Starting = 1; Starting < (countGroup + 1); Starting++)
 {		
       std::vector<string> ReadInData;
       ifstream ReadFile(ReadInGroup[Starting].c_str());

to

for (int Starting = [B]0[/B]; Starting < countGroup [B]/* + 1*/[/B]; Starting++)
 {		
       std::vector<string> ReadInData;
       ifstream ReadFile(ReadInGroup[Starting].c_str());
mitrmkar 1,056 Posting Virtuoso

You need to use the new_end iterator that the unique() produced.

std::sort(ReadInData.begin(), ReadInData.end());
vector<string>::iterator new_end = std::unique(ReadInData.begin(), ReadInData.end()); 
for (std::vector<string>::iterator it = ReadInData.begin(); it != new_end; ++it)
{
	outFile << *it << '\n';
}
mitrmkar 1,056 Posting Virtuoso

This should do

System::Diagnostics::Process::Start("c:\\test.txt");
mitrmkar 1,056 Posting Virtuoso

Have you tried ..
to show the sub-form from the main form (which has to be a MDIContainer)

// remove the taskbar style from the main form
this->ShowInTaskbar = false;
SubForm.MdiParent = this;
Subform.Show();

And when the sub-form closes, use ParentForm ...

// Restore the taskbar style of the main form
ParentForm->ShowInTaskbar = true;
Close();
mitrmkar 1,056 Posting Virtuoso

Can anyone tell me the reason we have to use pointers? Why can I code

char x[3]="ab"

? Does a pointer to a string point to the whole array?

Good questions ... I'd suggest you to take some time and see e.g.
http://publications.gbdirect.co.uk/c_book/chapter5/pointers.html

mitrmkar 1,056 Posting Virtuoso

This seems a bit more common error, the linker is now unable to find the photon's constructor, that's called from faisceau::initialize ...
Are you sure that you are also linking the photon.cpp's object file?

mitrmkar 1,056 Posting Virtuoso

The following can also be done .. it does not involve strcpy() or arrays,
instead it uses a single pointer (real_out_ptr)

char const * real_out_ptr = "This REALLY shouldn't have happened.\n";

int output_type = 1;

if (output_type == 1)
	real_out_ptr= "binary";
else if (output_type == 2)
	real_out_ptr = "octal";
else if (output_type == 3)
	real_out_ptr = "decimal";
mitrmkar 1,056 Posting Virtuoso

I'm actually not too familiar with g++, however after looking into google ...
one reason for "undefined reference to `main'" might be that:

you compiled a .cpp that does not contain main( ), but forgot to use the -c switch When compiling .cpp files that do not contain main(), use the command line
g++ -ansi -Wall -c myfile.cpp.

Will this solve anything?

mitrmkar 1,056 Posting Virtuoso

Have you actually ever succeeded in compiling/linking and running the program?

mitrmkar 1,056 Posting Virtuoso

Now it seems that you have stumbled upon another problem.
This is a linker error:
collect2: ld returned 1 exit status
which means that the code compiles OK but does not link for some reason.
Are you using some IDE or do you compile and link via shell/command line?

mitrmkar 1,056 Posting Virtuoso

Try rather ..

cout << [B]([/B]*iter[B])[/B].ponderation << "\n";
mitrmkar 1,056 Posting Virtuoso

Seems that operator << is unable to take a 'photon' as input.
You probably need to write something like:

std::ostream & operator << (std::ostream& s, const photon & p)
{
    // stuff the content of the photon into the stream ...
    //	s << p.abc << etc ...
    return s;
}
mitrmkar 1,056 Posting Virtuoso

One way to do it is to use std::ostringstream

int x = 123;
std::ostringstream osstream;
osstream << x;
std::string string_x = osstream.str();
// string_x is now "123"
mitrmkar 1,056 Posting Virtuoso

p.level is an integer, hence %d instead of %s ...

int viewcharacter()
{
    printf("Name:\t%s\n", p.name);
    printf("Level:\t%[B]d[/B]\n",p.level);
}
midimatt commented: Thanks for spotting my late night programming errors :) +1
mitrmkar 1,056 Posting Virtuoso

Use substr(), to extract '1234', you could do:

const std::string Value10 = "Number(1234)";

const size_t start = Value10.find("(");
const size_t end = Value10.find(")");

const std::string extracted = Value10.substr(start + 1, end - start - 1);

cout << "extracted: " << extracted.c_str() << endl;

In same, fashion you can extract 'Number' once you have a valid value for 'start' .
Note that, in case string::find() does not find any match, it returns the value std::string::npos, i.e. prepare to handle that case also, when you are looking up matches to extract sub-strings.

mitrmkar 1,056 Posting Virtuoso

This is practially pretty much what Lerner said ...

std::string Value = "a,b,c,d,e,f";
istringstream is(Value);
std::string s;
std::vector<string> v;

while (getline(is, s, ','))
{
    // add item
    v.push_back(s);
}
// iterate through the vector and output each item ...
for(std::vector<string>::iterator it = v.begin(); it != v.end(); it ++)
{
    cout << *it << endl;
}
mitrmkar 1,056 Posting Virtuoso

Maybe you could use strtod() as a 'workhorse' and switch to using a double instead of integer.
See http://www.cplusplus.com/reference/clibrary/cstdlib/strtod.html
For example,

char myStr[30] = "";
while(1)
{
    cout << "Enter a decimal number: (q to quit)" << endl;
    cin.getline(myStr, 30);

    if('q' == *myStr)
    {
         break;
    }

    char * endptr = 0;
    double dd = strtod (myStr, &endptr);

    // in this particular setup, *endptr is only allowed to be newline, nothing else,
    // i.e. even an extra space trailing an otherwise valid number invalidates the input ...
    if('\n' != *endptr)
    {
 	cout << "Invalid input ..." << endl;
    }
    else 
    {
        cout << dd << endl;
    }
}
mitrmkar 1,056 Posting Virtuoso
int Func3 ()
{    
     int Option;
     int   A = 2;   
     int B = 3;   
     double C = 2.5;         
     double D = 3.5;
     cout << " Enter your select: ";
     cin >> Option;

     if(1 == Option)
     {
          // Call func1() here
     }
     else if(2 == Option)
     {
          // Call func2() here
     }
     else
     {
          cout << "Wrong selection ...\n";
     }

     // return some value here ...
     return 0;
}
mitrmkar 1,056 Posting Virtuoso
System::Windows::Forms::DialogResult result = MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);

if(System::Windows::Forms::DialogResult::OK == result)
{
    // OK button
}
else 
{
   // System::Windows::Forms::DialogResult::Cancel == result
   // Cancel button
}
mitrmkar 1,056 Posting Virtuoso

Something like this ...

MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);
mitrmkar 1,056 Posting Virtuoso

You are having a following kind of construct, where the compiler does not know what Sort actually is inside the main() function.

#include <stdlib.h>
// Declaration of Sort commented out
// int Sort(const void *p, const void *p2);
typedef struct 
{
  int a;
} MYSTRUCT;
MYSTRUCT items[2];
int main(int argc, char* argv[])
{
	// Compiler complains "'Sort' : undeclared identifier"
	// (rightfully so, because declaration of Sort is commented out, above)
	qsort((void *)items, 2, sizeof(MYSTRUCT), Sort);
	return 0;
}

int Sort(const void *p, const void *p2)
{
	return 0;
}

So you need to declare your Sort() function before the function in which you call qsort().

mitrmkar 1,056 Posting Virtuoso

Change:
qsort((void*)word, wcount, sizeof(WORD), int(*Sort)(const void*, const void*));
to
qsort((void*)word, wcount, sizeof(WORD), Sort);

mitrmkar 1,056 Posting Virtuoso

Umm .. that should be easy to solve, I take that you have also declared the Parse() function, so the Sort() function should be declared in same fashion.

mitrmkar 1,056 Posting Virtuoso
int Sort(const void *l, const void *r)
{
        WORD *left = (WORD *) l;
        WORD *right = (WORD *) r;
        int n;

        if(left->count == right->count){
                n = strcmp(left->count, right->count);
                return n;
        } if(left->count > right->count){
                return 1;
        } else {
                return -1;
        }
}

Your sort function works right out-of-the box, after you have changed:

n = strcmp(left->count, right->count);

to

n = strcmp(left->word, right->word);

Only one function is incorporated there regarding the whole function of the program, and that's where I am appending all the processes.

OK .. then have to insert the qsort() call in that function, just be sure that all the input has been parsed before you call qsort().

mitrmkar 1,056 Posting Virtuoso

Because pl and pr both are pointers to void, you cannot use them as such to access the data they point to. Hence you need to type cast them properly before usage.
The only correct choice here is to cast them to (WORD *), nothing else will do.