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

computer won for me but I had to sort of force it to win. It appears to first check if it needs to block before it checks to see if it can win. Maybe you need to reverse those two checks. (I didn't look at the code, I just compiled and ran it)

I had to add #include <string> in each of the *.cpp files because my compiler, vc++ 2010 express, doesn't add it by default. Otherwise there were no other compiler errors or warnings -- Good Job :)

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

well then access the string just like you would the character array. Put this in a loop: if( !isalpha(name[i]) ) If name is std::string why are you not using std::cout instead of printf()?

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

how is name declared? Assuming name is a character array you will want to look at each character and use isalpha() to determine whether or not the character is a-z or A-Z.

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

For testing out the two programs you could do them both on the same computer. For more extensive tests use two computers (or computer and laptop) you connected via LAN. I don't think you can make your server program run on someone else's computer without their permission.

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

The stack parameter to those two functions have to be passed by reference, not by value int nPush(int b, stack<int>& a) Also you have to initialize the value of k before using it on line 49.

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

Look at the structure and figure it out for yourself what the problem is. Learn to do a little research on your own and it will save you lots of time and effort.

If you display the value of time_t all you will see is a very large number that means nothing to you. It is the number of seconds since 1970.

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

pragma startup

As for the times, it will depend on the operating system.

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

enter the time as normal and the program converts it to time_t

int hour = 10;
int minute = 30;
int duration = 4; // 4 hours
struct tm* tm;
time_t theTime;

theTime = time(0); // get current date/time
tm = localtime(&theTime); // convert to structure
tm->tm_hour = hour;   
tm->tm_minute = minute;
theTime = mktime(tm);  // convert struct to time_t

// now calculate the end time.  Just add the hours and/or minutes
// and the function mktime() will adjust all other values as
// necessary to normalize the structure.
tm->tm_hour += duration; // add the hours
theTime = mktime(tm);  // convert struct to time_t
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would probably use containment. Don't use the name 'time' because that symbol is already used in time.h

class localtime
{

};

class date
{

};

class timedate
{
  localtime tm;
  date dt;
};
Fbody commented: Agreed, containment is much easier. :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

convert it to an integer before comparison if( atoi(system.stocknumber) > 7) Your program should validate that the user entered all digits before doing that otherwise atoi() will produce meaningless results.

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

Problem 2: put the times and their duration in an array, then search the array. You might need to use the complete day and time in case duration is beyond 24 hours.

struct booktime
{
   time_t starttime;
   time_t endtime; // start time plus duration
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to make them a string, such as

char buf[40];
int hour = 1;
int minute = 25;
sprintf(buf,"%02d:%02d", hour, minute);

That's the easiest way to do it. It can also be done using stringstream.

Or if all you want to do is display them cout << hour << ':' << minute << '\n';

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

>>theft can *also* be defined as charging 10x the actual value of something
That's not theft -- its capitalism. You have a choice whether you want to buy those items or not. We choose to give McDonalds $4.00 for a 5 cent piece of burned meat between two pieces of bread. We choose to give Microsoft $150 (or whatever the cost) for Windows 7. We don't have that choice with theft.

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

why don't you ask them???

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

There is tons of information available via google

odbc tutorials

odbc c++ libraries

SQLAPI++

SqLite

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

I never wrote a game in my life, so I'll take your word for it :)

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

It's now been four years since the original article was posted here. c++ is still alive and thirving languge. D?? I don't know a single person who uses it.

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

So you think theft is ok ??? Do you also like to spend some time in prison? Theft is generally illegal in every nation on Earth, and in some countries you might get your hand cut off. Just because you don't want to pay the price for something doesn't give you the right to steal it.

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

I was in the Air Force 23 years and moved 22 times. A few times it was just from one house to another at the same military installation. If you have more than 4 years service in now it will be to your advantage to go all the way to retirement. I'm now at age 67 reaping the benefits of all those years, especially the medical benefits.

As for the degree, you will want to look closely at the coures offered for each then choose the one that best fits your goals.

As for salary, depends on where you are at. Here in the mid-west the salary for someone with a few years experience is progably $60-100K/year. If you work for Microsoft I'd expect the salary to be double or tripple that.

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

the loop should be something like this. And do not dynamically allocate array a because it is causing you a memory leak (your program doesn't delete[] it). The array size is small enough that dynamic allocation isn't necessary anyway on most modern operating systems such as MS-Windows and *nix.

int povtorenie(struct node* call)
{
	char a[20];
	strcpy(a,call->regnomer);
	call = call->next;
	while(call!=NULL)
	{
		if(strcmp(call->regnomer,a)==0)
			return 1;
		call = call->next;
	}
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Search amazon.com for the books. Is it too early? Not if you have understood those two books and successfully coded most of the problems at the end of the chapters. In that case you will probably have little problems understanding Windows Forms.

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

On today's computer there is little or no performance difference between floats and doubles. Years ago all floats had to be converted to doubles before FPU processes them. In some cases that may still be true, but no all. I understand some FPUs can handle both floats and doubles without conversion.

Here is one thread that talkes about the performance differences. At no time has floats ever been faster than doubles.

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

Either you are a very very fast programmer, or you cheated and plagiarized someone else's poorly written and non-standard code.

Fbody commented: Agreed +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is why we need guns for protection. I just love stories like this with happy endings :)

Glass_Joe commented: Best grandma ever +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are asking me to write the code for you, the answer is no. Try to do it yourself and post the code you tried. Try it out with pencil & paper first so that you can figure out in your head what has to be done. Then use a simple example, such as some three letter word.

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

One way to do it is to copy the string backwards into another character array.

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

Thank you for spending many years in our military -- I for one know what that is like and am able to better appreciate the sacrifices you are making.

As for that "high paying" job --- what do you consider to be high paying? And where? A bachelor's degree will certainly open a lot of doors for you, as for certs they are almost ignored. If you are considering military retirement at 20 years service you might want to consider cross training into one of the computer related fields. That will give you the experience you might need to make yourself even more competitive in the civilian work force.

As for whether you should be a BS in Management Information Systems (MIS) or Computer Science (CS) it depends on how much mathahetics you like. CS is more math and hardware technical oriented than MIS. MIS is more for solving business problems using programming and databases, not as theoritical as CS.

IT cllge stdnt commented: Thanks for posting and the advice!! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What's the problem? And next time use code tags

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

Why did you create two threads for the same problem??? See your other thread for solution.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
/* initialise triangular matrix to zero */	
for(i =0; i < dimention; ++i)		
   for(j =0; j <= i+1; ++j)			
    lower_tri[i][j] = 0;

The above causes buffer overrun. The inner loop should be < not <=

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

the array has to be deallocated in the reverse order that it was allocated

for(i =0; i < dimention; ++i)
	free(lower_tri[i]);
free(lower_tri);

If you get seg fault with that then it means the program has been corrupted somewhere.

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

function read() can not return a pointer to an object that is declared locally on the stack. Why? Because stack objects are destroy immediately when the function returns.

There are two ways to fix the problem
(1) in read() declare matX as static, such as static struct matrix matX; The static keyword makes the object persistent, very much like a global object.

(2) declare matX as a pointer then call malloc() to allocate the memory for it. main() will have to free() the memory when done with it.

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

That's because conrol is not returned back to Forms until after the function ends that adds the strings in the list box. It doesn't repaint the list box immediately after adding a string to prevent flicker and optimize performance. It would be exceedingly slow and awful looking if it had to repaint the form each time a string out of several hundred were added. I'm not well enough acquainted with Forms programming to know if you can add event hanlers to the list box or not.

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

If you are using VC++ 2010 (or 2008) you can create CLR Forms application in which you can easily create text boxes to display the information from the file. google for clr tutorials and you will find out how to do that.

I though you said the program reads the data from a text file. But with #6 I'm not so sure.

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

You need to force Form to repaint itself before each Sleep(). I'm not sure how to do that (I don't normall write CLR code) but here is a start.

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

Picture

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

foo() is nothing more than a generic function to illustrate a problem. You said in your original post that you wanted a function that returns a pointer to a structure, and that function foo() does exactly that.

If that is not what you mean, then you will have to post some code to show what you want.

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

You use the pointer operator -> to access structure members. See line 18 in the code below for example.

struct person
{
   char lname[80];
   char fname[80];
};

struct person* foo()
{
   struct person* p = malloc(sizeof(struct person));

   <snip>
   return p;
}

int main()
{
   struct person* p = foo();
   printf("Last name is %s\n", p->lname);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your picture illustrates an array with 4 stars, not 3.

Break them down into smaller sets of pointers which will be easier to comprehend. The code below assumes the last item in each array is a NULL pointer so that the program will know where the end of the array is at. That avoids the problem of having to pass the array sizes along with the pointers.

void foo(char ****menuptr)
{
   int i, j;
   char ***menus = *menuptr;
   for(i = 0; menus[i] != NULL; i++)
   {
      char** list = menus[i];
      for(j = 0; list[j] != NULL; j++)
      {
         printf("%s\n", list[j]);
      }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

on line 3: 1 and 4 have to be enclosed in quotes just like A and F.

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

Don't you have a text book to study?

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

All you need is three very simple if statements, something like below

if string length != 2 then error
if string[0] < 'A' || string[0] > 'F' then error
if string]1] < '1' || string[1] > '4' then error

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

@andro: this is C forum, not C++. And you used void main() instead of int main().

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

Why is your program reading the file one character at a time? Words are always separated with white space(s) (spaces and/or tabs). If you call fscanf() that function will read only words for you. You don't have to reinvent the wheel, but just use the functions that are already available to you.

Next you have to have some way to keep all those words in memory so that they can be counted. One way to do that is to have an array of structures, where the structure contains the word and an integer that is the count of the number of times that word appears in the file.

struct words
{
   struct words*next;
   char* word;
   int count;
};

That will let you maintain a linked list of the words. If you don't know about linked list yet then you can just make an array of those structures and increase the array size as necessary while reading the file. See malloc() and realloc() functions to do that.

When the program reads a word search the linked list or array for that word to see if its already in memory. I it is, then just increment the count variable. If it is not in the linked list or array you will have to add a new node.

Then you will have to sort the list in ascending order by the count. This is where that comparison function will have to be changed because qsort() will pass pointers to …

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

Your compar function is wrong. qsort() sends two pointers to the compare function int compare(const void* s1, const void* s2) In your case it will send two strings, so your compare function needs to typecase the void* to char*

int compare(const void*s1, const void* s2)
{
   return strcmp((const char *)s1, (const char*)s2);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I keep getting an 'argument not declared in scope' error, even though his works perfectly

Talk about a contridction of terms! You get compile errors but yet you claim it works perfectly :icon_eek:

Solve the problem in one of two ways: cop3530::hash_table<int, int, cop3530::linear_probe> ht(10); or adding this at near the top of the *.cpp file using namespace cop3530;

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

I use inline functions frequently in header files but they are really only useful for functions that are only one or two lines. If you do this for functions on in a c++ class then you must declare them with the inline keyword (or __inline depending on the compiler). If you don't then you will wind up with duplicate function declarations when the header file is included in two or more *.cpp or *.c files. inline is not necessary for cass methods

Note that compilers are not required to honor the inine keyword. inline is only a hint to the compiler how to optimize the program and they are free to do as they wish.

class Foo
{
public:
   Foo() { _x = 0; }; // an inline constructor
   int getX() {return _x;} // another inline method
   void setX(int x) {_x = x;} // another inline method
private:
   int _x;
};

// an inline function
_inline int bar(int x, int y)
{
   return x*y;
}

If you use Visual Studio Pro version and create a COM or ATL project the IDE will generate several header files that contain inline class methods that are 20-30 or more lines long. I usually move them into an implementatin file to make the header file easier to read.

You will also see inline class methods used extensiely in the STL header files such as <string>, <vector>, <list>, <fstream> etc. I believe the reason is because they are templates. I won't even …

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

Yes you can mix both C and CPP files in the same project. C functions can not generally call c++ functions, but c++ functins can call C functions. You just have to tell the compiler which c functions you want to call from the c++ functions.

This is how you might code a header file that can be included in both C and C++ files. This example shows how to declare a function foo() that is contained in a C file and called from a c++ file. The _cplusplus may be something else on your compiler so check your compiler's documentation to find out what it uses. One way of easily doing that is to look at stdio.h and find out how your compiler handles that macro.

#ifdef __cplusplus // if compiling c++ code
exern "C" {
#endif
extern int foo();
#ifdef __cplusplus // if compiling c++ code
}
#endif