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

>>is it possible to have two different names of one functions

Short answer: no

However, what you could do is put all the common code into a single function which is called by the other two functions

int common_code(int info)
{
   // blabla
}

int do_my_server(int info)
{
    common_code(info);
}

int do_my_client(int info)
{
    common_code(info);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That data file may not be in the directory (folder) you think it is. Move it to the same directory where the *.exe executable program is located.

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

>>1) How could time (in the form of HH: SS above) be represented in the array, so >>that they can be subtracted? How do you subtract when

Don't put the dates/times in an array at all.

Convert the time read from each line into seconds, then all you have to do is subtract the seconds. Something similar to time_t variables.

One way to do that is to populate a struct tm structure with the date/time, then call mktime() to get the time_t object. You will have to parse the line read from the file
Example:

#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;

int main()
{
    struct tm time;
    time_t t1, t2, t3;
    char c;

    // populate first time
    std::string t = "2008/11/22 14:59"; // assume this is read from file
    stringstream str(t);
    memset(&time, 0, sizeof(struct tm));
    str >> time.tm_year >> c; // get year and / character
    str >> time.tm_mon >> c;
    str >> time.tm_mday;
    str >> time.tm_hour >> c;
    str >> time.tm_min >> c;
    // subtract 1 from month so that it is between 0 and 11
    time.tm_mon -= 1; 
    // substract 1900 from year
    time.tm_year -= 1900;
    t1 = mktime(&time);

// now to the same with the other times t2 and t3
}
tux4life commented: You're always great in simplifying things :) +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem might be anywhere between you and Microsoft. You obviously can get to other sites such as DaniWeb so malware on your computer is unlikely.

I moved your thread over here so you can get some serious help. Geeks' Lounge isn't the place for support questions.

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

what line number does that error occur on ?

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

At line 17 of the code you posted the variable j is only visible in that for loop. If you want to use that variable again on line 21 it will have to be declared again just like it was on line 17. Another way to fix the problem is to declare that variable on line 14 similar to the way those other integers were declared, then remove the declaration on line 17 to make line 17 similar to line 21.

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

worked for me :)

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

A little googling

How Object-Oriented Programming Started

by Ole-Johan Dahl and Kristen Nygaard,
Dept. of Informatics, University of Oslo

SIMULA I (1962-65) and Simula 67 (1967) are the two first object-oriented languages. Simula 67 introduced most of the key concepts of object-oriented programming: both objects and classes, subclasses (usually referred to as inheritance) and virtual procedures, combined with safe referencing and mechanisms for bringing into a program collections of program structures described under a common class heading (prefixed blocks).

The Simula languages were developed at the Norwegian Computing Center, Oslo, Norway by Ole-Johan Dahl and Kristen Nygaard. Nygaard's work in Operational Research in the 1950s and early 1960s created the need for precise tools for the description and simulation of complex man-machine systems. In 1961 the idea emerged for developing a language that both could be used for system description (for people) and for system prescription (as a computer program through a compiler). Such a language had to contain an algorithmic language, and Dahl's knowledge of compilers became essential.

More of this article here.

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

>>There are several free compilers, such as Code::Blocks, Dev-C++, and VC++ 2008 Express.
( Note to OP: I am talking to Ancient Dragon, this has got nothing to do with you)
I never knew Code::Blocks and Dev-C++ are compilers!! I thought they were IDEs ;)
Or am I sensing it right?

Technically you are right, they are IDEs. But they are distributed with the programs that do the actual compiling, the libraries, and the header files. So IMHO the term "compiler" encompasses all of those packages.

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

you can't do it with that compiler. Get yourself a free copy of a modern compiler and it will create all the nodes you want. There are several free compilers, such as Code::Blocks, Dev-C++, and VC++ 2008 Express. Just google for them and you will find them.

I ran your program on my computer and VC++ 2008 Express and it had allocated over 3,000,000 nodes before I stopped it.

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

Change proc_new_disk_reques() to return a pointer and your program should compile

DiskRequest*  proc_new_disk_request(int procnum, int sectornum, ReadOrWrite rw)
{
	DiskRequest *new_request;
	
    new_request = (DiskRequest *) checked_malloc(sizeof(DiskRequest));
    new_request->dr_procnum = procnum;
    new_request->dr_sectornum = sectornum;
    new_request->dr_rw = rw;
    new_request->dr_next = NULL;
    
    return new_request;
}

Note that at some point in the program that pointer has to be free()'ed.

xyster commented: Amazingly fast reply and so helpful in his reply. Thankyou! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want the friend function then preceed the function name by :: return ::gcd(nominator, denominator);

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

tux> If your computer has more than a GB of RAM that wouldn't be a problem

But the OPs computer crashed with just a megabyte-sized array. :( So it's not about total space available, but about how much stack space is reserved (which of course can be increased with a compiler option).

You are right. My computer has 8 gig RAM, compiled with VC++ 2008 Express, and it crashed when I ran it.

booker commented: GRATE KNOWLEDGE +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

win32 api function is very simple -- just a one-liner MessageBox(NULL, "Testing", "Title Here", MB_OK); MFC is even a little easier. I think the .NET version is just as easy System.MessageBox(<blabla>); or something like that.

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

depends on the compiler and operating system. most likely that matrix is overrunning stack space.

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

Do you also think that unix and programming on unix sucks?

Absolutely yes. I hate *nix because its just too damn complicated to get anything done. There are, however, a few features I like, such as shell programming, awk and sed. MS-Windows batch files aren't in the same league with *nix shell programs. But doing simple things like installing programs on *nix is a nightmare.

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

you may have to write the drawing code yourself, but QT is a GUI library that is portable between MS-Windows a *nix. There a few others too, I think wxWidgets is one of them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
ReadFile(com_port,&output,readlength,p_readlength,NULL);
std::cout << output<<std::endl;

In the first line the 4th parameter is nothing more than a pointer to the 3d parameter. declaring another pointer is not necessary. And do not put & symbol whan passing character arrays. ReadFile(com_port, output, readlength, &readlength, NULL); >>std::cout << output<<std::endl;
That's the reason for the garbage characters -- when ReadFile() returns the input buffer is not a null-terminated string. before printing the string either null-terminate it or print it one character at a time. readlength will contain the number of bytes that were read at the port. I would suggest you clear the input buffer before calling ReadLine()

memset(output, 0, sizeof(output));
ReadFile(com_port, output, readlength, &readlength, NULL);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I also don't know why every place there is a colon and capital D I am getting an emoticon.
Yea -- click the Advanced button, scroll down to the checkbox Disable Smilies In Text. I fixed it for you.

I think there were lots of changes between 2003 and 2005/8. Never used 2003 so I can't help you.

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

Looks like all it has to do is return the value returned by getPoly()

[edit]What ^^^ said too :) [/edit]

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

>> // not sure what goes here

Neither do we since you didn't post enough of the class to know what is supposed to be returned. Its supposed to return a reference to something, but we have no idea what.

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

you are doing too much work!

#include <iostream>
using namespace std;
#pragma warning(disable: 4996)

const int HEIGHT = 5;
const int LENGTH = 4;
int main()
{
   int **pointerArray, *dummyPointer;

    pointerArray = new int* [HEIGHT];

    for (int cnt = 0; cnt < HEIGHT; cnt++)
	    pointerArray[cnt] = new int [LENGTH];

    for (int cnt1 = 0; cnt1 < LENGTH; cnt1++)
    {
        dummyPointer = pointerArray[cnt1];
	    for (int cnt2 = 0; cnt2 < HEIGHT; cnt2++)
	    {
	        *dummyPointer = cnt2;
	        dummyPointer++; 
	    }
    }

   
    for (int cnt1 = 0; cnt1 < LENGTH; cnt1++)
    {
        dummyPointer = pointerArray[cnt1];
	    for (int cnt2 = 0; cnt2 < HEIGHT; cnt2++)
	    {
	        cout << *dummyPointer << endl;
	        dummyPointer++; 
	    }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I put your program all in one file and here is the result (using VC ++ 2008 Express)

#include <ctype.h>
#pragma warning(disable: 4996)


void strToUpper(char *str)
{
	int i = 0;
	while(str[i] != '\0')
	{
		str[i] = toupper(str[i]); //reset bit 5
        ++i;
	}
}

int getCommandId(char *word)
{
	FILE *fp;
	char buf[256];
	char *tok;
	int i = 0;

	fp = fopen("commands.txt", "r");
	if(fp == NULL)
		return -1;
	
	strToUpper(word);
    i = 0;
	while(fgets(buf, 255, fp) != NULL)
	{
        strToUpper(buf);
		tok = strtok(buf, " ");
        ++i;
		while(tok != NULL)
		{
			if(strcmp(tok, word) == 0)
				return i;

			tok = strtok(NULL, " ");
		}
	}

	return 0;
}

int main(int argc, char* argv[])
{
	char word[256];
	int id;

	strcpy(word, "move");
	strToUpper(word);
	printf("%s", word);
	id = getCommandId(word);

	if(id == -1)
		perror("Error");
	else if(id == 0)
		printf("No such command.");
	else
		printf("ID: %d\n", getCommandId("move"));

	getchar();
	return 0;
}

The main problem with the program is that main() calls getComandId() twice. In the printf() line, instead of calling getCommandId() again (line 60 of the code I posted) just use the return value from the previous call.

getCommandId() also needs to close the file before exiting, which I did NOT correct.

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

>>str[i++] &= 0xDF; //reset bit 5
Programming is not about trying to be cute, but about writing code that you and everyone else in the world can easily comprehend. str[i] = toupper(str[i]); ++i;

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

in main.cpp, delete line 2 #include "hello.cpp". NEVER EVER include a *.c or *.cpp file in another one like that. If main.cpp needs to know about that function, then just use extern keyword, like this:

#include <iostream>
using namespace std;

extern int funny_words();
// blabla

Also, funny_words() is declared to return an integer. You must add code to do that on line 16. If you don't need it to return anything then change it to void function void funny_words()

Salem commented: You should have mentioned the "#define GEQUAL" horror as well :) +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After allocating the memory for the array you can not increment or decrement the pointer. When you do, you destroy the memory that was allocated because the pointer to the original memory is lost.

If you want to increment/decrement pointers, then create another pointer for that purpose, but leave the original pointer unchanged.

tux4life commented: I can't explain this in a better way :) ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

PointerArray is a two-dimensional array, right ? You have to allocate both dimensions

PointerArray = new int *[HEIGHT]; // allocate an array of int pointers
for(int i = 0; i < HEIGHT; i++)
    PointerArray[i] = new int[LENGTH];

The above will allocate what would be statically allocted like this: int PointerArray[HEIGHT][LENGTH];

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

I tried to compile using VC+ 2008 Express:

your program has a lot of unused variables that you need to clean up to prevent millions of warnings about it.

It also contains a couple real syntax errors. But you probably missed your compiler's error messages with all those warnings about unused variables.

line 556: what is setup ?

line 608: wnat is noplay ?

[edit]Ok noplay is a label. But you can get rid of it by removing the goto statement.

function checkblack() does not return a string. That could be a huge problem for anything calling that function.

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

What I have done is create a structure with all the information I want exchanged between the two windows. When the 2nd window is created pass a pointer to the structure to the 2nd Window so that it can fill in the information. Once Window 1 regains control it will have the information in the structure.

Another approach is for Window #2 to send a private message to Window #1 that contains the information. Then Window #1 can update itself with the info. This works well when there is only a small amount of text to be transferred between the windows.

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

>>Would it just be done like this
No. See my previous example

strcpy(output,name) // strcpy() only for the first one
strcat(output,addr); // strcat() for all the others
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>#include <afxres.h>

That header file is only useful in Microsoft MFC programs. For Dev-C++ you might as well delete it.

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

>>I need to copy the name, addr, telephone, carinfo, payment array to the output array. How would I go about doing that

use strcat() to concantinate c-style character arrays. You just need to make sure the destination string is big enough to hold all the strings you want to put into it.

char destination[255] = {0};
strcpy(destination "Hello ");
strcat(destination, "World");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm partial to the use of "strftime()"

And I did all that in only three lines of executable code ;)

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

use the functions in time.h to get a struct tm, then use sprintf() to format the filename

char filename[255];
struct tm* tm;
time_t now;
now = time(0); // get current time
tm = localtime(&now); // get structure
sprintf(filename, "file_%02d%02d%04d", tm->tm_mon+1,
    tm->tm_day, tm->tm_year+1900);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are compiling for UNICODE, so param1 should be L"%d" to force the conversion of the string to wchar_t*. Or it might be preferable to use _TEXT("%d") so that you can turn off UNICODE if you want to and not have to change that line.

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

you need to use CString's Format() method. It works exactly like printf().

CString txt;
txt.Format("%d", m_AMC.get_FramesDrawn()));
MessageBox(txt, MB_OK);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to use function prototypes

void run(); // this is a function prototype
void command( const char* cmd); // another function prototype

int main()
{
    run();
}

void run()
{
    "code"
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

a 2d vector vector< vector<string> > lists;

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

string::npos is what the std::string.find() method returns when the search string is not found. Read about it in the documentation for the string class.

replace() will replace one instance of a character or string of characters with another. However, for a single character its just as easy to replace the character yourself. y[found] = 'x';

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while(found!=-1)
	{
	found=y.find(x,ind);
	ind=found+1;
	
	if(found==-1)
	{break;}

The above can be better written like this because it doesn't require so much code and if statements.

while( (fund = y.find(x,ind)) != string::npos )
{
       ind=found+1;
    // etc etc
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If those are the only command-line options why do you need Boost? That's like swatting a fly with a sludge hammer.

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

Try GetVersionEx Windows API function.
See MSDN article(s): http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx

Agree -- that provides more info than the registry link I posted.

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

Its in the registry HKLM\Software\Microsoft\Windows NT\Product Name

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

config files have a general format as <tab name>=<value> What that program is doing is finding specific tag names and, if found, reading the value field.

Line 26 is a loop that reads all the lines in the file. Then 28-35 check for specific tag name and, when found, reads the value field of the line.

If you are still confused then compile the program for debug and use your compiler's debugger to single step through the program, then inspect the value of the variables to see what the program did.

kelechi96 commented: Thank You +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

its a poorly written program.

>>istringstream sin(line.substr(line.find("=") + 1));
The program will more than likely crash if line does not contain '=' or if that symbol is the last character on the line.

>>if (line.find("num") != -1)
line.find() doesn't return -1, it returns string::npos.

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

why are you opening the text files in binary mode??? Just open it in text mode

// not that ios::in and ios::out flags are not needed for ifstream and
// ofstream
ifstream infile (ascifile); 
ofstream outfile( binfile );
while( infile >> Index1 >> Index2 >> simvalue )
{
    outfile.write((char *)&Index1, sizeof(Index1);
    outfile.write((char *)&Index2, sizeof(Index2);
    outfile.write((char *)&simvalue, sizeof(simvalue);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After line 19 you need to flush the input buffer of the '\n' character. cin.ignore(1000,'\n'); should do the trick.

hurbano commented: very helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

which line did the error occur on ? And make sure spelling and capitalization are all consistent.