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

Why does that first error not supprise me. :eek: The so-called code you posted in red is not code at all. I have no idea what it is. You can't just type in some crap into the program and expect the compiler to understand it.

The only valid error is the first one -- just ignore the others. Fix the first error and the others will go away.

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

most common way is via ODBC -- use google to search for ODBC and you will find some c++ classes.

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

<<mod edit: threads merged -- original context is now somewhat wacky>>

why don't you get with Omher to solve your common assignment?

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

>> int elements[] ={0};

This array only has one elelement and its value is 0

>> while(integer != -1)

I'm supprised this loop works at all! variable integer is unitialized and contains some random value.

>> elements[counter]=integer;
you can't resize an array like that. If you want to make the array dynamic then make it a pointer and use new (if this is a c++ program) or malloc (c programs) to adjust it to the desired size.

int* elements = 0;
...
...
   elements = new int[counter];

// or
   elements = malloc(counter * sizeof(int));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks, I think this will help, I have only two question:
1. I didn't undertand the line:

fudge = (ULONG_MAX - previous_count) + now;

The more I think about this the more I think the value only needs to be ULONG_MAX. After roll-over only need to add ULONG_MAX to get the 64bit tick count.

fudge = ULONG_MAX;

2. What will happen if I change the variable type from "_int64" to "ULONGLONG"

Nothing. ULONGLONG is just a typedef for _int64 except _int64 is signed.

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

something like this?? But of course this won't work either when 64bit integer get data overflow, and assumes this function will get called more frequently than once or twice every 49 days!

#include <windows.h>
#include <limits.h>

_int64 GetMyTickCount()
{
	static _int64 previous_count = 0;
	static _int64 fudge = 0;

	_int64 now = GetTickCount();
	if(now < previous_count)
	{
		fudge = (ULONG_MAX - previous_count) + now;
	}
	previous_count = now;
	return now + fudge;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ULONGULONG is a 64bit integer. Yes its bigger than DWORD (unsigned long) but it will have the same identical problem if your program runs long enough without stopping.

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

there is no bug in GetTickCount(). The reason it wraps around is that a DWORD can only hold a finite number of milliseconds and it reaches its maximum at 49.7 days. So if your program runs longer than that without being stopped and restarted, then you will have to compensate for that feature

Checking to find out if GetTickCount() returns 0 is very unlikly to occur -- you need to check if the most recent value is less than some previous value.

You might consider saving the vales in a 64-bit integer, which will give you a much longer time period. when the value returned by GetTickCount() rolls over you can easily calculate the new value (add new value to previous value and store in a 64-bit number).

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

there are a lot of errors in that code. For example, in a linked list, the next item is supposed to point to the next node in the list.

start->next >>> node->next >>> node->next ...

The end of the linked list is noted when next == NULL.

Your program does not set the next member, so consequently it does not create a linked list.

void create_linked_list ()
{
	start = NULL;
        end = NULL;

	for (int i=0;i<wordCount;i++)
	{
		if (strlen(vayArray[i])==5)
                {
                      p = new for_char_5;
                      p->next = NULL;
		     strcpy(p->vh5,vayArray[i]);
                     if(start == NULL)
                     {
                            start = p;
                            end = p;
                      }
                     else
                     {
                            end->next = p;
                            end = p;
                      }
                }
	}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

create a structure that contains the items for each record in the file. Then either create a linked list or an array of these items and read the file into the structures. You will want to rewrite all this information before the program ends so that the changes will be remembered the next time you run the program.

>>where am i going to load the file.
when the program first starts.

>>cos searching in the file is very easy
searching in-memory is a whole lot easier than searching in a file, especially if you want to use a BST.

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

>>we are forced to use VOID* ARRAY ... :-)
then my idea of using unions will not work. you will just have to typecast whenever the program accesses the array.

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

Hi!

I built this class, however when I executed my program the memory run out quickly, because I wasn't making any "deletes", so I added the delete in the destructor, but It crashes there... what's wrong?

Nothing wrong with what you posted -- its impossible to tell what the proglem is because you didn't post enough code. Check for (1) writing outside allocated array bounds, (2) using uninitialized pointers.

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

maybe this will help

#define _WIN32_WINNT 0x500
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
   HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd,SW_MAXIMIZE);
    cout << "Hello World\n";
    cin.get();
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes -- how else can the program pass the correct data type to printf(). There is another solution -- create a union of data types than an array of union objects

typedef union
{
    short sVal;
    int iVal;
    long lVal;
    float fVal;
    double dVal;
}DATA;

...
DATA* array = malloc(some_number * sizeof(DATA));
...
scanf("%d",&array[loop].iVal);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

a matter of correct typcasting. Note placement of asterisks and other typcasts in the scanf() line. I did not run your program so I don't know if it really works right.

case 1  : { user_array=(int*)malloc(size_of_input*(sizeof(int)));
	      if (user_array==NULL) { printf("MEM ALLOC FAILED\n"); exit(1); }
		 else
		   {
		   printf("Enter Data to Array\n");
		   for (loop=0;loop<size_of_input;loop++)
			scanf("%d",&((int*)user_array)[loop]); }
	      }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm running Apache 3.0, and have a c++ cgi-bin program working fine with Apache...

Then your program is NOT "running fine with Apache" :cheesy: Did you check the read/write permissions on the directory in which the program is attempting to write?

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

Does anybody knows what comes instead of MESSAGE_MAPs within an addIn (beause it seems like message maps are not acceptables with addIns) ??
or may be no one is interested in this thread any more ...
I feel like im the only one how is interested in this thread :(

No replies doesn't mean nobody is interested -- it means nobody knows the answer to your question. When you start out by saying "Does anybody knows ..." more than likely the slience means No and I don't have time to do your research for you.

BEGIN_MESSAGE_MAP is an MFC thingy -- why would you expect to be able to use it in non-MFC projects???

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

in *nix they are shared libraries

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

I think what you will probably want to do is remove the word(s) from the strings. If you use c++ and std::string, use string's find method to locate the word then use its substring method to remove it.

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

writing your own malloc is not all that easy as you can see from the GNU implementation. Its largly os-dependent and is probably not something an entry-level programmer could accomplish. And nobody could write it in just the few minutes that an interview could accommodate.:eek:

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

Thanks Ancient Dragon for your answer. As for FindFirstFile() and FindNextFile(), could you please tell me which C++ library should be included in order for the two functions to be available? I was not able to find them in C++ Builder but that doesn't mean they do not exist at all.
Thanks again!

You will also need to read the Microsoft docs for those functions -- here

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

>>It seems like a big problem

Yes, it is a lot more complex than what one might expect, and you probably won't find anybody willing to do all that for free. There is no easy solution to what you want. You are going to have to bite the bullet and do your own research.

you will also find some information at www.codeproject.com. When you get there, enter "Office Automation" in their search engine and it will give you links to a few articles and examples. like this one.

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

K&R It's a book by the creaters of the C programming language

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

Sorry, but I don't think you can write a c++ program to fix that problem.:mrgreen:

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

The functions FindFirstFile() and FindNextFile() will iterate the all the files and sub-directories. For each file they return a structure that contains the filename, attributes, size and other data. Check the file's attributes to see that it is a normal file and, if it is, your program can open and edit it.

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

you probably should post your question on adobe's "user to user" forum.

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

Yes, Dave, my comment was incorrect.

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

>> error C2220: warning treated as error - no 'object' file generated

post the errors that appeared before that one. That error only says the compiler stopped because of previous errors.

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

Why are you casting strlen. There's no need for that.

there is if you use vc++ 2005 -- strlen() returns size_t (unsigned int) with that compiler.

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

your program works ok with my compiler (VC++ 6.0). what compiler and os are you using. did you include stdio.h header file? And after changing the value of the "a" variable don't forget to recompile your program.

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

Question?

Should you be using malloc in c++, isn't it frowned upon?

Yes -- but it can be much more serious problem that just "frowned upon" because malloc() does not call class constructors or destructors.

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

The correct typecast is (see place ment of the asterisk)

// C example
(struct message_from_server*)malloc(sizeof(struct Message_from_server)); 

// C++ example (keyword struct not necessary)
(message_from_server*)malloc(sizeof(Message_from_server));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are compiling a C program as C++ (with .cpp extension instead of .c extention), then you will have to typecase malloc because the compiler is compiling it as a c++ program, and c++ requires the typecase. If, on the otherhand, the file is *.c extension, then no typecase is necessary (permissible but not necessary).

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

you need to make the linked list global so that it is visible to all other functions.

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

look you your book for fstream class. If it isn't there then you wasted your money buying that book -- pawn it off on some other sucker.

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

I think you should research Microsoft Office Automation. This is not something that you can do in one evening, requires quite a bit of reading and studying. I don't think you will find easy answers to your questions. You may also want to search www.amazon.com for related books on M$ Office Automation.

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

>>I like this one but I want to avoid declaring all strings at once and then choosing (honestly I might have dozens of 20-entry arrays, I'm not sure how many arrays I will need yet).

If all the strings are hard-coded in the program, they take up the same amount of memory wherever you put them. The compiler will put all those strings into some (probably) read-only memory block, so your concern is a non-issue. Probably a better solution is to put the strings in a text file then read them into memory at runtime. you can create a text file similar to standard ini file

// strings.txt
[entry-1]
Entry 1
Entry 2
...
Entry n
[entry-2]
Entry A
Entry B
...
[entry-n]
...

your program will look for the tag it needs then read the strings until ene-of-file or another tag name is encountered. This method gives you a lot more flexibility because you can freely add more strings to the text file and not worry about adding/recompiling your program.

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

The code I posted earlier was wrong -- I edited it to use correct code.

Arrays can only be initialized the way you are trying to do it when the array is first declared. After that you have to initialize it one at a time.

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

use a vector if you want an array of strings.

#include <string>
#include <vector>
using namespace std;

int main()
{
   vector<string> array(5); // initialize to be an array of 5 strings

   switch(z)
   {
        case 0:
              array[0] = "entry 1";
              array[1] = "entry 2";
              ...
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe this will help. But this will be a great deal easier if you learn to use VB.NET -- you can mix and match VC++.net and VB.net functions.

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

This looks like it should be a linked list of messages. You need to allocate an object that represents the head of the linked list, then add nodes to it. One way might be like this

void sqEnqueue(struct Message_from_server** head, const char *s)
{
    struct Message_from_server* new_node = malloc(sizeof(struct Message_from_server));
    new_node->s = malloc(strlen(s)+1);
    strcpy(new_node->s,s);
    new_node->next_message = NULL;
    if( *head == NULL)
    {
        *head = new_node;
    }
    else
    { // add new_node to the end of the linked list
              // locate end of list
            struct Message_from_server* tail = *head;
            while(tail->next_message != NULL)
                tail = tail->next_message;
            // found end of list, now add the new node to it
            tail->next_message = new_node;
     }
}

// this is how to call the above function
int main()
{
   struct Message_from_server* head = NULL; // top of linked list
   sqEnqueue( &head, "Hello");
   sqEnqueue( &head, "World");

// don't forget to delete the list when done with it.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

DirectX for MS-Windows os. is free, and includes some examples. Definitely not for beginners.

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

post code. We are not mind readers you know.:mrgreen:

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

what is variable "address"? where did you declare it?
also post the code that wrote the file. and the first line or two of the file contents.

>>static_cast<long>(address);
that line does nothing at all. you might as well delete it.

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

use ODBC calls to connect to databases. See google for lots of examples and a few c++ classes. But you cannot do that at all with Turbo C because that compiler is too old, you will have to upgrade to a new compiler like Borland Builder, Dev-C++, or Microsoft VC++ 2005.

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

I guess you expect everyone to be mind readers. You will have to post your code

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

no -- you have to write your own. Makes for good practice sharpening your programming skills.:cheesy:

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

What is this 'google' you talk of? :?:

Its a search engine for the internet. see www.google.com. type in a key word(s) and it will try to find it. Sometimes it works ok, but often it will return trillions of answers :mrgreen:

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

you won't be able to simulate it on either *nix, MS-Windows or MAC. But you might be able to do it in MS-DOS 6.X and earlier because it doesn't have the multi-process activitiy that the other os have.

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

I can“t have a new one.
I'm working in investigation at the university and this is the one that they gave me to install...

well, in that case change the code. declare variable i at the top of the function and remove the declarations from each loop. Its not really all that hard to do.

If you can't change the code, then you are SOL :mrgreen: