mitrmkar 1,056 Posting Virtuoso

Thanks people. I had something along the lines of mitrmkar's thing before I checked, but I still don't get the -52 stuff

When you introduce a variable and don't assign it any value, the variable exists but it's value is simply random because it is not initialized. In general, initialize the variables you use to a known value.

mitrmkar 1,056 Posting Virtuoso

Maybe it's best if you post the whole function.

mitrmkar 1,056 Posting Virtuoso

First of all, please learn to use code tags.

It looked like you are maybe implementing the functions inside main(), which is not allowed. You cannot nest any functions, it is strictly forbidden, like for example

int somefunction()
{
    int some_value;

   void nestedfunction()
   {
        // nestedfunction()'s code here ...
       return;
   }
    return some_value;
}

You can also do without function prototypes in some cases, for example

int somefunction()
{
    // somefunction()'s code here ...
    return 0;
}
int main()
{
     // call somefunction() ..
     int i = somefunction();
     return i;
}

Or the same with a prototype ...

// prototype
int somefunction();
int main()
{
     // calling somefunction() at this point can be done
     // because the above prototype tells the compiler 
     // how to deal with somefunction() ...
     int i = somefunction();
     return i;
}
// implementation
int somefunction()
{
    // somefunction()'s code here ...
    return 0;
}

Hopefully you got the main idea how to organize your code.

mitrmkar 1,056 Posting Virtuoso

my DLL is working and i know that for sure because when i use an already posted and compiled dll injector it works.

Umm .. out of that I sort of figured that you already have a working injection (?).

If not, then again, the example code you've posted, seems to be capable of doing the injection. So, I take that your DLL along with that example code, is doing something that breaks the injection or maybe you are erroneously expecting something to happen in your DLL. Really difficult to say anything more, not knowing a bit of your DLL's code.

mitrmkar 1,056 Posting Virtuoso

The first time you print 'i', it has the initial unknown value it got from 'ch'.

If you add the green and red lines below, you'll probably get the idea ...

// morechar.cpp -- char and int types contrasted
#include <iostream>
int main()
{
        using namespace std;
        char ch;   //declare a variable ch

        // ch is not initialized to any known value ...
        cout << "uninitialized ch is: " << ch << endl;

        int i = ch;     // stores same code in an int

        cout << "i, being assigned the uninitialized value of ch, is: " << i << endl;

        cout << "Enter any ASCII character:\n";
        cin >> ch;
        // align i with ch ...
        i = ch;
        cout << " The ASCII code for " << ch << " is " << i << endl;

        cout << "Adding one to the character code takes you to the next character.\n";
        ch = ch + 1;    //change the character code in ch
		i = ch;
        cout << "The ASCII code for " << ch << " is " << i << endl;
        
        //using the cout.put member function to display a char
        cout << "Displaying  char ch using cout.put(ch): ";
        cout.put(ch);

        //using cout.put() to display a char constant
        cout.put('!');

        cout << endl << "done." << endl;
        return 0;
}
mitrmkar 1,056 Posting Virtuoso

Someone gave me this yesterday but it doesnt seem to work?
I dont really want to try and pull apart an example that doesnt work as well it may be all wrong and theres no point in learning something that is wrong.

What does it fail to do? What code do you have in the .DLL?

I gave the code you've tried a test ride and it worked. The code for the .DLL that I injected is below ...

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved)
{
    if(ul_reason_for_call == DLL_PROCESS_ATTACH)
    {
        MessageBox(NULL,
                "inject.cpp -> DLL_PROCESS_ATTACH", 
                "Injected",
                MB_ICONINFORMATION);
    }

    return TRUE;
}

Please note that the topic is non-trivial, so everything might not work out of the box.

mitrmkar 1,056 Posting Virtuoso

Have you considered what the code does when e.g. OpenProcess(), GetModuleBaseName() or GetWindowTextA() fails?

mitrmkar 1,056 Posting Virtuoso

Below you have three function prototypes ..

int hipvalley (void); 
int cricketvalley(void);
int ridgeangle(void);

You need to implement them too, i.e.

// implementation of function hipvalley () ...
int hipvalley (void)
{
    int some_value;

    // some code here

    return some_value;
}
mitrmkar 1,056 Posting Virtuoso

How do I read up on exec? What, man exec in the terminal?

Here is the link John A posted ...
http://www.opengroup.org/onlinepubs/000095399/functions/exec.html

mitrmkar 1,056 Posting Virtuoso

Hi Thanks again,

My final problem is I do not know how to do this with functions.

Can you lead me in the right direction?

Well, the first required function is the bool isATriangle(const double s1, const double s2, const double s3); With regard to that, you could have something like ...

// a function prototype
bool isATriangle(const double s1, const double s2, const double s3);

int main()
{
    double s1, s2, s3;

    // code here that gets the values for s1..s3

    bool bTriangle = isATriangle(s1, s2, s3);

    if(bTriangle)
    {
        // it is a triangle
    }
    else
    {
        // it is NOT a triangle
    }

    return 0;
}

// function definition
bool isATriangle(const double s1, const double s2, const double s3)
{
    // three values are passed in ...

    if( /* add code to check here whether it is a triangle */  )
    {
        // it is a triangle
        return true;
    }
    else
    {
        // it is NOT a triangle
        return false;
    }
}
mitrmkar 1,056 Posting Virtuoso

Maybe this will do ... RedrawWindow(hConsoleWnd, 0, 0, RDW_INVALIDATE); hConsoleWnd is the console's window handle.

mitrmkar 1,056 Posting Virtuoso

This is a modified version of niek_e's code

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    ifstream in;
    in.open("c:\\yourfile.txt");
    if (!in.is_open()) 
    {
        cout << "Can't open file\n";
        return 1;
    }
    
    string line;

    // read one line at a time
    while (getline(in, line))
    {
        stringstream sstrm(line);
        
        string word1, word2;

        if(sstrm >> word1 >> word2)
        {
            // two words extracted ...
            MyFun(word1, word2);
        }
    }

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

no numeric value activates my functions.

Two changes ...

# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898
using namespace std;

double Rise1 = 0; //for vertical data input of 1st roof slope-- Rise1
double Rise2 = 0; //for vertical data input of 2nd roof slope-- rise
double Eave = 0; //for data input- eave orientation angle-- 0 through 180,
		 // 181 through 360 is identical to 0 through 180.
double a; //input data conversion for both cricket, and hip/valley routine.
		 // cross product angle equation.
double Width = 0; //data input for cricket routine-  cricket width.
char  ch1, ch2, ch3; //character choices


float atan(float);
float acos(float);
float sqrt(float);

int hipvalley (void);//(float argc, char *argv[]); 
int cricketvalley(void);//(float argc, char *argv[]);
int ridgeangle(void);//(float argc, char *argv[]);


int main()
{
	
	for(;;) //this is an infinite loop. One of the choices
		    // will end it.
	{
		cout << "         Copyright 2001, Welcome to the Angle Finder Program.          " << endl;
		cout << "        This program is designed to take only numeric values.          " << endl;
		cout << "       Make certain you only input numbers. Otherwise it will exit.    " << endl;

		cout << " Please choose:  1 for the Hip/Valley Angle. "         << endl;
		cout << "                 2 for the Cricket Valley Angle. "     << endl;
		cout << "                 3 for the Ridge Angle "               << endl;
		cout << "                 0 to exit. "                        << endl; …
mitrmkar 1,056 Posting Virtuoso

its been done in VB so i dont see why it cant be done in c++.....

http://www.codeproject.com/KB/threads/winspy.aspx

mitrmkar 1,056 Posting Virtuoso

can anybody solve this problem..

Linking...
gdtopng.obj : error LNK2001: unresolved external symbol __imp__gdImageDestroy@4
gdtopng.obj : error LNK2001: unresolved external symbol __imp__gdImageCreateFromGd@4
Debug/gdtopng.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

gdtopng.exe - 3 error(s), 0 warning(s)

Try linking with bgd.lib.

mitrmkar 1,056 Posting Virtuoso

I tried it, and recieved an error,

[Linker error] undefined reference to `WinMain@16'

You are trying to build a Win 32 GUI program and you have no WinMain(...) - hence the error.
If you want to build a GUI program, then write the WinMain(...) too, see
http://msdn.microsoft.com/en-us/library/ms633559.aspx

Otherwise, start a new Win32 Console Application project, which uses the int main() .

mitrmkar 1,056 Posting Virtuoso

Oh I see -- that function is meant for MFC.

No, it's rather a generic function for sending a string to a debugger.

mitrmkar 1,056 Posting Virtuoso

Then why use it since you have to delete them all before releasing the program ?

Some wrapping around it is obviously needed, as for example MFC's TRACE macros.

mitrmkar 1,056 Posting Virtuoso

It appears to be sort of like assert(), where you can add debugging comments which don't show up when the program is compiled for release mode.

OutputDebugString works the same regardless of release/debug build.

mitrmkar 1,056 Posting Virtuoso

it doesnt move through.. i does the same as my first one, just displaying only the second name now

To loop through all the 12 names, you can use ...

for(int ii = [B]0[/B]; ii < sizeof(names)/sizeof(names[0]); ++ii)
{
    cout << "player: " << names[ii] << endl;
}

Note that the first index is zero (not 1) and the last is 11. You must not access names[12] because that would be out of bounds.

mitrmkar 1,056 Posting Virtuoso

How about adding a new member function, say SetStats(), which takes the user's choice and initializes a default constructed Character, i.e.

// default constructed
Character player;

cout <<"\n\nBefore we begin, please select your class."
	 <<"\nEnter a 'W' for Warrior or an 'M' for Mage. ";

char classChoice;
cin >> classChoice;

// initialize the player according to choice
player.SetStats(classChoice);

player.DisplayStats();

SetStats() might also validate the given choice and return true/false accordingly.

mitrmkar 1,056 Posting Virtuoso

What i want to do is write some of the rows of a report style CListCtrl with a color and other rows with another color, but if I switch the color with SetTextColor the color of the text in the entire control switches, i want it to switch just for the rows I set till the next color switch

Is this possible? If you know it is, plz enlighten me :)

thx a lot

This link might help
http://msdn.microsoft.com/en-us/library/ms364048(VS.80).aspx

mitrmkar 1,056 Posting Virtuoso

If you use the new operator on a class, say

class dummy { public: string f; };
int main(int argc, char *argv[]) {
  dummy *p = new dummy;
  return 0;
}

do you have to use the delete operator on p ? (since, apparently, it utilizes new.)

Yes, when you want to release that memory, 'delete' needs to be issued.

Salem commented: Yes indeed +17
mitrmkar 1,056 Posting Virtuoso

What in the world does line 20 do?

A tutorial on it ...
http://www.cprogramming.com/tutorial/initialization-lists-c++.html

mitrmkar 1,056 Posting Virtuoso

Does the telnet part work properly if you issue the commands directly from command line?

mitrmkar 1,056 Posting Virtuoso

Post the complete code you have. If it is large, zip it and attach the zipped file.

mitrmkar 1,056 Posting Virtuoso

I have no way to tell if there is a memory leak or not during run-time.

One basic detector (covers malloc/new) can be found e.g. here
http://www.codeproject.com/KB/applications/visualleakdetector.aspx
and google finds more ...

mitrmkar 1,056 Posting Virtuoso

Is there any way of getting the selected date in a CDateTimeCtrl in a CString or char* or anyting?

Here is one way ..

CTime time;

if (GDT_VALID == DateTimeCtrl.GetTime(time))
{
    CString strDate = time.Format("%d.%m.%Y");
}

See the CTime::Format(...) for more information on the the formatting options

mitrmkar 1,056 Posting Virtuoso

I got assertion failure error...

Can you tell which ASSERT fails?

mitrmkar 1,056 Posting Virtuoso

Try changing '\r' to '\n' i.e.

send("telnet 192.168.3.100[B]\n[/B]", 150);
mitrmkar 1,056 Posting Virtuoso

You might use std::string ...

string data;
string line;

while (getline(indata, line)) 
{
    data += line + '\n';
}
mitrmkar 1,056 Posting Virtuoso

a gets a negative value (-1) in the following loop.

// checks diagonal up-right movement
	for(a=i-1,b=j+1;a>=0, b<N;a--,b++) {
		if(board[a][b]==1) {

The comma operator a>=0, b<N is not doing what you probably expect.

mitrmkar 1,056 Posting Virtuoso

I tried to delete all the struct definitions and start over. I found when I use SceneParticulation, the error will be raised. Otherwise everything goes ok. But what's wrong in this definition:

struct SceneParticulation
{
public:
    SceneParticulation(){};
    ~SceneParticulation(){}; // here the program stops and fails
    ParticleSystem SPParticle;
};

Nothing is wrong with the definition as such, however, you also need to consider the member variable ParticleSystem SPParticle - what does that object hold and what will its destructor do. I think you should drop the habbit of memcpy'ing objects which are more than simple structs - simple meaning structs that only contain primitive types (int, char etc) and nothing else. I.e. instead of memcpy, write copy constructors/assignment operators where needed.

mitrmkar 1,056 Posting Virtuoso
for(int count = 0; count < Size && capeFile >> F.date; count++)
	{
		capeFile >> F.FlightNum;
	}

The above code works for input like:

13-02-2004 123
13-02-2004 123456
13-02-2004 123456789

Maybe your input is of different format?

mitrmkar 1,056 Posting Virtuoso

Such as.............

You might post the relevant code, so we could see where it goes wrong.

mitrmkar 1,056 Posting Virtuoso

If I use the [] operator and return a reference, is there any way to mark that indice when a value is assigned to it?

Maybe you could use a bitset for tracking the assignments.
Two things I noticed:
- use of realloc() would result in fewer malloc/free calls
- you should test malloc's return value against NULL

mitrmkar 1,056 Posting Virtuoso
// what will 'cmp' be ...
const int cmp = s_manip.compare("abc","abcd");

// what will 'cmp' be ... const int cmp = s_manip.compare("abc","abcd");

I've tested that... it turned out to be false. I don't understand the point you were trying to make here.

My bad ... sorry about that one ...

mitrmkar 1,056 Posting Virtuoso

Perhaps ...

double indexLowTemp()
{ind=1;
for (a=0;a<col;a++)
 {if (low<=temp[a][0])
	{low=temp[a][0];
	 ind=a;
	}
 }

// output low temp ...
cout << low;
mitrmkar 1,056 Posting Virtuoso

Emphasizing line #48, the mc object is on stack (i.e. not allocated by new), so when it goes out of scope, its destructor gets called automatically. Generally you don't call destructors, those get called via delete or automatically in case of stack objects.

mitrmkar 1,056 Posting Virtuoso

that smiley not meant to be there

FYI, there is the 'Disable smilies in text' option below the 'Submit Reply' button ... ;)

mitrmkar 1,056 Posting Virtuoso

what advantage they would get from it.

To avoid name (identifier) clashes.

mitrmkar 1,056 Posting Virtuoso

Nevermind about the comparison, I created a class that does char pointer to char pointer comparisons.

// what will 'cmp' be ...
const int cmp = s_manip.compare("abc","abcd");

A diagnostics suggestion, add the following destructor

~Game_Object()
{
    std::cout << "~Game_Object(): " << objName << std::endl;
}

It will tell you that the memory management is not right.

You already have a Game_Object * in obj, you don't have to allocate and assign a new Game_Object ..

obj[i] = new Game_Object[1]; // you don't need this line
obj[i] = tempPtr[i];

Then strlen() returns the length of a string excluding the terminating NULL character but strcpy copies the string and appends the terminating NULL character <-> you have many one-byte-off memory allocations/assignments/overwrites there.

Then an example of a practice you effectively use

struct test
{
    int member_var;
    
    test() : member_var(0){}
    ~test(){}

    void f()
    {
        cout << member_var << endl;
    }

    static test & getObj()
    {
        test * p = 0;
        return *p;
    }
};

int main(int argc, char *argv[])
{
	test & obj = test::getObj();
	obj.f();

	return 0;
}

I wonder why are you not using std::string?

I still suggest to drop the manual allocation/reallocation schemes and use a STL container.

mitrmkar 1,056 Posting Virtuoso

Please use code tags when posting code, see here
http://www.daniweb.com/forums/misc-explaincode.html

mitrmkar 1,056 Posting Virtuoso

Honestly, my compiler is not giving me these warnings! What compiler should I update to in order to get these messages?

Those are not compiler warnings but instead run-time checks wrt heap usage. The compiler will not catch the errors that occur in the program, but the run-time checks will alert you on the spot. Try e.g. a VC ++ Express 2008.

It appears that you are not yet fully understanding about memory allocation/deallocation, so
if you use the malloc/free, every pointer you 'free' must have been malloc'ed, no exceptions.
if you use the new/delete, every pointer you 'delete' must have been new'ed, no exceptions.

I'm also trying to say that if you have a non-dynamic 'object', you must not issue free nor delete on a pointer to such object. This in mind, go through the code and see what happens with e.g. [B]bound[/B] ("Bound"), [B]adephi[/B] ("Adephi"); .

mitrmkar 1,056 Posting Virtuoso

do you have any clue on the function lol?

You might try FlashWindow() or FlashWindowEx().

mitrmkar 1,056 Posting Virtuoso

Thank you very much for the clarification.

I made the changes. Here are the files with the revisions.

Hmm, wouldn't it be better to drop usage of malloc()/free() since you are working with objects instead of raw native types i.e. consistently use new/delete. And maybe consider e.g. STL list for storing objects/object pointers, to save yourself the hassle of memory management.

Anyway, note that you must not issue free() on anything that has not been malloc'ed. That is just what is now happening in addObject(), that crashes the program at very early stages (before main() is called).

mitrmkar 1,056 Posting Virtuoso

Anyone got anything?

There is one 'oddity' that needs to be pointed out, namely usage of '\\' as end-of-comment marker. The backslash at the end of the single line comment works as a line continuation character and hence the next line is also taken as comment. You have one instance of this happening, i.e.

//------------end of house-keeping------------------\\
		   int AirportsTL::getAirportsNum (){ <- this line turns into a comment

So it's better to use something else to end the comment lines.

You have some type mismatches there + something else too

setScheduel(FlightsTL plan); 
// maybe you meant just (?)
setScheduel(plan); 

// ----------------------------------
// Fplan is not of type FlightsTL
setScheduel(Fplan);

// ----------------------------------
// you don't have a ctor taking only 3 arguments
Airports.push_back(Airport(code,minCon,desc));

// ----------------------------------
// C is not of type Flight
Airport a("syd",0.30,"Sydney domestic airport",C);
mitrmkar 1,056 Posting Virtuoso

Oh that's interesting. I was told to delete memory that was dynamically allocated and that malloc was one of the types that you could delete?

On a side note I'm using Dev-Cpp 4.9 and I haven't updated my compiler so I don't get those kind of warnings unfortunately.

Whenever you use malloc() then free the memory using free().
Whenever you use new, then free the memory using delete.

mitrmkar 1,056 Posting Virtuoso

After a quick look into it, I suggest that you get rid of malloc() usage. You are using 'delete' on memory that has been malloc'ed - that must not happen.
Then about 'delete', you only can delete something that has been allocated by 'new', consider

class a
{
public:
    a(){}

} instance; // an instance of class a

void somefunction(a* aptr)
{
    delete aptr;
}
int main()
{
    a * aptr = new a;

    somefunction(aptr);  // this is OK

    somefunction(&instance);    // <- must not happen

    return 0;
}

There were some other issues too, but I think first you could make sure that the basic memory operations are in order.
When I tried the program, addObject(adephi); causes the run-time to report damaged heap.

mitrmkar 1,056 Posting Virtuoso

okay, thats what I thought...so now I know I'm doing something wrong...I'm missing something somewhere, because I can't seem to pull the values from main and print them....now originally, I thought that was because I was screwing up the function that was supposed to print them to the screen...but maybe it's in the setters in my class, am I doing those wrong? (they are on the previous page)

You need to assign the values in the ctor (they do not get assigned automatically)

telnumber::telnumber (string i_npa,string i_nxx,string i_line)
: 
  npa (i_npa),
  nxx (i_nxx),
  line (i_line)
{ }