mitrmkar 1,056 Posting Virtuoso

was created using borland are there any changes that must be done on it before using it in VC++

Just occurred to me that probably you'll have to do some changes before using LIB.exe. Apparently the .DLL functions use __stdcall calling convention, so you'll have to modify each function so that they'll conform to the MS's name decoration convention. In practice, every function is to be appended an '@', followed by the number of bytes taken by the arguments.

I.e. if you have a library function void __stdcall function(char *, char *, char *); it would be function@12 in the .def file.

Furthermore, in your project which will include the generated .lib + its accompanying header,
1) use extern "C" {} in the header file to wrap all the exported functions.
2) make sure that the exported functions are seen as __stdcall , either use the /Gz switch or explicitly add the __stdcall to each function prototype.

Note that LIB.exe will additionally prefix every function with an underscore. So if you'll look into the .LIB's exports by e.g. dumpbin.exe /EXPORTS LT360LIB.lib you'll see something like _LT360LIB_CloseLink@0 (assuming LT360LIB_CloseLink does not arguments)

If you end up having mixed-up calling conventions, your program will crash at run-time.

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

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

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
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

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

Some more corrections in red ...

/*------------------------------------------------------------------
* Assignment 7: FIRST LINKED LIST ASSIGNMENT.
*Worth: 50 points
*Made by: Samuel Georgeo (max11)
create
an in-memory SERIALLY linked-list database program which
displays a menu screen.
-------------------------------------------------------------------*/

#include <stdio.h>
#include <iostream>
#include "/var2/local/include/getch.h"
using namespace std ;
/*-----------------------------------------------------
* MAIN PROGRAM STARTS HERE
-----------------------------------------------------*/
int main(int argc, char *argv[1])
{
	char  b;
	while(1)
	{
		putchar('\n') ;
		puts("\t\te) Enter a new agent");
		puts("\t\tl) List agents in file");
		puts("\t\tn) Next Struct in List");
		puts("\t\tp) Prev Struct in List");
		puts("\t\tq) Quit program");

		if (phere)  // avoid segfault for nonexistant record
		phere->print_rec() ;

		putchar('\n') ;
		b = getch();
		switch(b)
		{
			case 'e':
				if(!p) {
					p = new prs;
					if (!p) exit(-1) [B];[/B]
					p [B]-[/B]> next = p [B]-[/B]> prev = p;
					edit_rec (p);
				} else {
					phere = p [B]-[/B]> prev;
					pnew = new prs;
					if (!pnew) exit(-1)[B];[/B]
					p [B]-[/B]> prev = pnew;
					pnew [B]-[/B]> next = p;
					phere [B]-[/B]> next =[B]???[/B];
				} // You missed this out..
				break;

			case 'l':
				puts("you typed l") ;
				break;
			case 'n':
				phere= phere->getNext() ;
				break;
			case 'p':
				phere= phere->getFrom();
				break;
			case 'q':
				puts("you typed q") ;
				return 0 ;
				break;
		};  // switch case b
	};
	deletelist (head);
}// main
William Hemsworth commented: Well spotted :) I gave the more obvious problems +2
mitrmkar 1,056 Posting Virtuoso

I guess you are after this

class test
{
    bool is_good;

public:
    test() : is_good(true){}

    operator void * ()
    {
        if(is_good)
            return (void*)this;
        else
            return 0;
    }

    void go_bad()
    {
        is_good = false;
    }
};

int main()
{
    test t;

    if(t)
        cout << "good\n";
    else
        cout << "bad\n";

    // change the state ...
    t.go_bad();

    if(t)
        cout << "good\n";
    else
        cout << "bad\n";

    return 0;
}
William Hemsworth commented: Great simple answer. Thanks :) +2
mitrmkar 1,056 Posting Virtuoso

Actually no, I get an error message saying:
"cannot convert from std::string to const char."

The parameters for strcat are: (char*, const char).

I assume variable2 is std::string, in which case you are to use:

strcat(variable1, variable2.c_str());

Just in case you are not too familiar with std::string, you can avoid strcat() completely, by simply:

std::string variable1 = "something" ;
std::string variable2 = " else";
// concatenate the strings
variable1 += variable2;
CodeBoy101 commented: Perfect!! +1
mitrmkar 1,056 Posting Virtuoso

Is there a way to convert from an integer to a string?

Yes, one way of doing it is ...

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
	int x = 123;

	stringstream ss;
	string s;

	ss << x;
	ss >> s;

	cout << s;

	return 0;
}
CodeBoy101 commented: Perfect!!! +1
mitrmkar 1,056 Posting Virtuoso

The following might work for you, assuming that the values are always comma-separated

string line;
	double x,y,z;
	char dummy; // for skipping commas

	while ( getline(canopyfile, line) )
	{
		stringstream iss(line);

		if(iss >> x >> dummy >> y >> dummy >> z)
		{
			holder.setx(x);
			holder.sety(y);
			holder.setz(z);

			canopyvec.push_back(holder);
		}
		else
		{
			// failed to extract 3 values
		}
	}
cbattagler commented: Thank you again +1
mitrmkar 1,056 Posting Virtuoso

Seems that a static function has to be defined in the class itself and not outside the class.

That is not true, you really can define the static member function outside the class. Maybe you've applied the 'static' keyword also to the definition of the static member function.

Anyhow, for the sake of clarity, the following setup should compile without a glitch.

your main .cpp file

#include "date.h"
int main()
{
    Date::set_default(9,7,2000);
    Date S(3,7,1991);
    S.addyear(18);

    return 0;
}

your date.cpp file

#include "date.h"
Date Date::default_date(9,7,2000);
const Date Date::default_date_const(9,7,2000);

Date::Date(int dd=0,int mm=0,int yy=0)
{
	d=dd? dd:default_date.d;
	m=mm? mm:default_date.m;
	y=yy? yy:default_date.y;
}

Date& Date::addyear(int n)
{
    y +=n;
    return *this;
}

void Date::set_default(int dd,int mm,int yy)
{
    Date::default_date.d=dd;
    Date::default_date.m=mm;
    Date::default_date.y=yy;
}

your date.h file

#ifndef DATE_H_DEFINED
#define DATE_H_DEFINED

class Date
{
	static Date default_date;
	static const Date default_date_const;
	int d,m,y;        
public:		
	static void set_default(int dd,int mm,int yy);
	Date(int,int,int);
	Date& addyear(int);
	int show_date(){return d;}
	int show_month(){return m;}
	int show_year(){return y;}
};
#endif // #ifndef DATE_H_DEFINED
mitrmkar 1,056 Posting Virtuoso

1) To make the call Date::set_default(), needs the set_default() to be a static member function.
2) It is not enough to declare a static member variable inside the class declaration, you also need to define and optionally initialize it.

class Date
{
    // a non-const default date
    static Date default_date;

    // a const default date
    static const Date default_date_const;

    int d,m,y;        

public:
    static void set_default(int dd,int mm,int yy);
    Date(int,int,int);
	
    <snip>
}; // class Date ends here

// the non-const default date defined & initialized here
Date Date::default_date(9,7,2000);
// the const default date defined & initialized here
const Date Date::default_date_const(9,7,2000);

int main()
{
    // Date::set_default() is now a static member function,
    //  so the following call works
    Date::set_default(9,7,2000);
    Date S(3,7,1991);
    cout<<"Date"<<S.show_date()<<"-"<<S.show_month()<<"-"<<S.show_year()<<"\n";
    S.addyear(18);
    cout<<"Date"<<S.show_date()<<"-"<<S.show_month()<<"-"<<S.show_year();
    return 0;
}
Nick Evan commented: thanks for the correction +5
mitrmkar 1,056 Posting Virtuoso

Shouldn't you change from 'int *prt;' to 'decode *prt;' ?

Then you could change to

[B]ifstream &[/B] decode::loadDecode(ifstream &fin) 
{
    fin >> alphabet;
    fin >> code;

    return fin;
}

// ... and use it like

while (de.loadDecode(fin))
{
    prt = new decode(de);
    // you are not checking the result of allocation here,
    // if it failed, you are about to experience a crash ...
    decodes.insert(*prt);   //refer to lab 8
}

It's a very bad practice to use !fin.eof() within a while loop like, you are doing now.

Salem commented: Good call on the use (and abuse) of eof() +16
mitrmkar 1,056 Posting Virtuoso

You could write a condition statement also so that the variable is on the right side of the expression, i.e. if (0 == noModsPassed07) This way your compiler will spot an obvious error, i.e. if (0 = noModsPassed07) will not compile.

Sky Diploma commented: Nice Way!! +1
mitrmkar 1,056 Posting Virtuoso

Should sky.exe >out.txt be written in a specific place? or anywhere else?

Specify any location of your choice that you have write access to.

Regarding the system() and std::string, you can use: system(some_string.c_str());

Nick Evan commented: You're right. I forgot about c_str() +5
mitrmkar 1,056 Posting Virtuoso

<< if I try to push changed data using function, I get just the same word n times:
That happens because you are pushing pointers to one single buffer you have in your whole program, and that buffer is char recordd[].
In other words, you can write to that buffer as many times as you wish, but the data that was last written to it, is the only data you ever can get out of it.

So, you need to allocate dynamic memory into which you copy the AD()'s output, that you eventually push onto the stack. Maybe you get the idea from the following ...

int main()
{
    POINTER start = NULL;
    char *DELIMITERS = " ";  
    char *str,record[100],*o;
    [B]int len;[/B] // holds the length of string that will be pushed
    char line[]="jjj   yyyy dfsfsd sdfsdf sdfsdfsdf sdfsdfsfd sdfasdfafs Intelect";
	
    str = strtok(line, DELIMITERS);
    // Consider recordd as just an intermediate work buffer 
    // for the AD() function
    char recordd[sizeof(record)] = {0};

    while (str)
    {
        // Pass the input to AD()
        AD(str, recordd);
        // Get the length of string and account for a terminating null char
        len = 1 + strlen(recordd);
        if(len > 1) // did AD() give some output?
        {
             // Allocate the memory needed to hold the string to push
             char * temp = (char *)malloc(len * sizeof(char));
             if(temp)
             {
                 // malloc() succeeded, now copy the data from recordd 
                 strcpy(temp, recordd);
                 // and push it
                 push(&start, temp);
             }
        }
        str = strtok(NULL, DELIMITERS); …
mitrmkar 1,056 Posting Virtuoso

A MSDN article
How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio 2005
http://support.microsoft.com/kb/828736
It assumes that you have a managed DLL + a native application. (Hopefully this one is of more use than the previous one.)

mitrmkar 1,056 Posting Virtuoso

If ScheduledIn will be of type char (i.e. char ScheduledIn) then you cannot use double quotation marks in the if expression, use ' ' instead ...

char ScheduledIn;
...
ScheduledIn = toupper(SchecduledIn);
if (ScheduledIn == 'Y' || ScheduledIn == 'N'))
{

}
Ancient Dragon commented: You are right -- I should have caught that too :) +28
mitrmkar 1,056 Posting Virtuoso

vardas is an array of 25 Strings. So if you want to keep it that way, you need to use
something like: gydmas[1].vardas[[B]some_valid_index_here[/B]] = Edit21->Text;

En1ro commented: Thanks for help ;) +1
mitrmkar 1,056 Posting Virtuoso
c++noobie commented: Thank you very much. You helped me solve this. +1
mitrmkar 1,056 Posting Virtuoso

>>function named swap that takes exactly three arguments (the array name and the two >>subscripts of the array whose values are to be swapped).
>>The swap function should not return any value.
>> Add both the prototype and the definition of swap to the program.

Your prototype's subscripts are wrong, you are trying to pass arrays of references to int,
instead the subscripts are simple integers telling the indexes whose data is to be swapped,
so

void swap(int [], int& [], int&[]);

turns into

void swap(int [], const int, const int)

The subscripts are declared as 'const', you could do also with plain non-const ints, i.e.

void swap(int [], int, int)

Then the selection_sort, the call to the swap() function is now readily in-place

void selection_sort(int a[], int n)
{
   int i, j, smallest;
   int temp;
   for (i = 0; i < n-1; i++) {
      smallest = i;
      for (j = i + 1; j < n; j++) {
         if (a[j] < a[smallest])
            smallest = j;
      }

        // swap the values at the indexes 'i' and 'smallest'
        swap(a, i, smallest);
//      int i, smallest;
//      int temp = a[i];
//      a[i] = a[smallest];
//      a[smallest] = temp;
   }
// A missing curly brace in your original code caused the
// [B]'swap' : local function definitions are illegal[/B]
// error message ... 
// You cannot define a function inside a function, ever, so
// here ends the selection_sort() function ...
[B]}[/B]

Here is the swap function to be filled in ...


       
mitrmkar 1,056 Posting Virtuoso

see getrusage(), e.g. here
http://linux.die.net/man/2/getrusage

adcodingmaster commented: good +0
mitrmkar 1,056 Posting Virtuoso

The output i am getting on the VB interface = ¯õ#;‘ƒ9s„‡Ñ'Ý¢@ýýýýÝ (21 bytes)
What can cause the problem...

There is no terminating null byte in the string, allocate 1 byte more and terminate the string yourself, e.g.

char* plaintext = new char[size + 1];
plaintext[size] = 0;
kartouss commented: Very helpful +1
mitrmkar 1,056 Posting Virtuoso

You need to tell the IDE to link with the Winmm.lib library also, so open
Project/Properties/Configuration Properties/Linker/Input
and append winmm.lib in the Additional Dependencies field.

Also, use the first block of code you've tried, i.e.

PlaySound(TEXT("test.wav"), NULL, SND_ALIAS | SND_APPLICATION);

mitrmkar 1,056 Posting Virtuoso

In your THREEDICE.H add the following forward declaration

#define THREEDICE_H
[B]class onedie;[/B]
class threedice
...

Then the statistics() function is a bit odd, if you think it will be called from e.g. main(),
it probably should look like

int main()
{
    const int roll_count = 200;
    int rolls[roll_count] = {0};
    // I'm not actually sure what the allresults should be
    int allresults[roll_count] = {0}; 
    // Then you can make the statistics() call ...
    statistics (rolls, roll_count, allresults);
    return 0;
}

void statistics (int rolls[], int count, int allresults[])
{
    threedice tryerluck;
    for(int i=0;i<count;i++)
    {
        tryerluck.rollem();
        rolls[i]= tryerluck.getsumFaces();
    }

    // and maybe do something here with the allresults too    
}
mitrmkar 1,056 Posting Virtuoso

Could you post the code that wraps CreateProcess?

mitrmkar 1,056 Posting Virtuoso

If you will not be using MFC (for any reason), check out ZedGraph
http://sourceforge.net/projects/zedgraph/

Ancient Dragon commented: Great suggestion :) +24
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

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

Since I don't know what the function is supposed to do, I cannot offer much advise. However, if you plan to change the values of the parameters passed into the function, you need to pass the parameters by reference, instead of by value. I.e.
public char CheckDir(int & row, int & col, int & selectedX, int & selectedY);

Ancient Dragon commented: The OP doesn't know what he wants to do either :) +24
mitrmkar 1,056 Posting Virtuoso

Just to give some basic ideas, you might do with the following simple setup, without linked lists involved at all.
Use a structure like e.g.

typedef struct 
{
    const char * _pWord; // pointer to the word
    unsigned int _nFreq;  // its frequency
}Entry;

To make it easy, have a fixed size table of Entry structs e.g.

#define MAX_WORDS 123
Entry table[MAX_WORDS] = {0};

and track the amount of used entries by e.g.

size_t nWordsUsed; // Increment when a word is inserted to the table

Write a function that parses the input i.e. splits the string to words, e.g.

void  Parse(char * pWords)

Write a function that handles inserting a word into your table (called by Parse()).

void Insert(const char * pWord)

Finally, use qsort() for sorting the table, you need to write a sort function of your own to supply to the qsort(), e.g.

int mySort(const void * pl, const void * pr)
{
     // Get the pointers to the Entry structs and compare
     Entry * pLeft = (Entry *) pl;
     Entry * pRight = (Entry *) pr;
     // compare ...
     // int result = ...
     return result;
}

In your sort function, first compare the frequency, if that's equal, let strcmpi() do the comparison. For more information on qsort() http://www.cplusplus.com/reference/clibrary/cstdlib/qsort.html
So your main function could look like ...

// global variables .. (here only for simplicity's sake)
Entry table[MAX_WORDS] = {0};
size_t nWordsUsed = 0;
int main(int …
VernonDozier commented: Thoughtful post +1
mitrmkar 1,056 Posting Virtuoso

Remove the & operator, tempString as such must be used in that scanf (tempString is a pointer, hence no need for &).

scanf("%s", [B]&[/B]tempString);

Then allocate memory before copying.

temp->artist = (char*) malloc(strlen(tempString)+1);
strcpy(temp->artist, tempString);

You may want to check that malloc() actually succeeded, (i.e NULL != temp->artist). Also remember to free() all the malloc'ed memory at some point.

mitrmkar 1,056 Posting Virtuoso

The errors boil down to the RationalInfo() function, even though you are not calling
it from anywhere, the compiler wants it to be OK, so fix it first or remove it if don't need it

int RationalInfo (int initialArray[][B][MAX][/B])
{
    [B]// You still need to declare the variables a and b here[/B]

    int quotient, remainder;
    float value;
    for (int i = 0; i <setArray; i++)
     {
         for (int j = 0; j < MAX; j++)
             {
                  initialArray [i+2][j] = initialArray [i][j] / initialArray [i+1][j];
                  
                  quotient = a/b [B];[/B]
                  remainder = a%b [B];[/B]
                  value = a/b [B];[/B]           
             }
     }

     [B]// You need to return something from this function[/B]
     return ???
}