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

Your program is missing a lot of ; statement terminators, such as the one on line 23 of the code you originally posted (there are several lines like that).

My compiler vc++ 2008 Express also coughs up warnings about assigning doubles to floats because you didn't add 'F' after a magic number, such as the 0.15 on line 23, instead of 0.15F. One easy fix for that is to declare variables as double instead of float.

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

i keep getting spam mail to my email address and its getting on my last nerve so I am asking a moderator to delete it or for people who help me get rid of it. Thanks for your help though with the line deletion for i just used a for loop and it works

If that is from DaniWeb, it isn't spam. You have an option set in your PROFILE to send you e-mails whenever someone posts a response to your thread. Click on "Contro Panel" at the top of the page in the yellow bar and turn that option off.

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

The problem might be compiler specific. I used VC++ 2008 Express and had no errors with the code snippet you posted. What compiler are you using?

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

please delete thread

Why??

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

delete lines 80 and 81 because those two variables are not needed.

Now all you have to add is a simple loop tocompare the letters of each string. If they are not then same then increment NumMissed counter.

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

Replace the history array with a binary data file. Of course that will slow down the program a great deal.

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

memory for that array is not layed out by pointers. The first 20 bytes are for the first string, that is followed by the next 20 bytes for the second string, etc. So fetchoutStr() needs to treat it as if it were just a single-dimension character array that can hold up to 10 20-byte strings.

int fetchroutStr(int numArgs, ...)
{
va_list arg_ptr;
int counter = 0;
int numParam = 0;
char *tempStr;
int args = 0;

va_start(arg_ptr, numArgs);
numParam = numArgs;

while(counter < numArgs)
{
tempStr = va_arg(arg_ptr, char *);
printf("\nFetch Pointer : 0x%p", tempStr);
printf("\nFetch Loop : %d - %s", counter, tempStr);

// printf("\nPointer 0x%p", &tempStr[1]);
// printf("\nIn loop: %d - %s", counter, tempStr[1]);
counter++;
}
va_end(arg_ptr);

strcpy(tempStr, "funcStr1");
printf("\nFetch Field 1 changed: %s", tempStr);
tempStr += 20; // advance to beginning of the next string
printf("\nFetch Field 2 changed: %s", tempStr);
strcpy(tempStr, "funcStr2");
// printf("\nfetch 2: %s", tempStr[1]);
return 0;
}

[edit] Or -- like Narue sayd ^^^ [/edit]

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

You are attempting to allocate 15000x15000x2 integers, or 1.800.000.000 bytes of memory, which is nearly 2 Gig. The limit of any 32-bit program is 2 Gig. You will either have to use a 64-bit compiler (and operating system) or settle for considerably smaller size of the arrays.

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

google is your friend. Here is a binary tree program written in C that was at the top of the google links. All you have to do with it is change the tree nodes to hold strings instead of integers and add an integer counter to count the number of times the word appears in the file, then read the file and insert the words. Your program will also have to first search the tree to see if the word already exists, and if it does then just increment its counter.

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

line 49 is missing { opening brace on that function.

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

Its not necessary to actually change the current working directory. See this code snippet for example how to do that.

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

Sounds like the M$ DLL is not located in one of the directories in your PATH environment variable. Most likely it should be in c:\windows directory or one of its sub-directories (system32?).

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

>>This one is not working too.

What exactly does that mean? I can not compile your program because my compiler does not support <sys/time.h>, gettimeofday(), or drand48().

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

>>while (status=2)

Use the boolean == operator there, not the assignment = operator.

>>The pointer says the error is in the line previous to main.
The line previous to main() is a blank line. Repost your current code so that we can see what you are talking about.

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

>> MessageBox(0, errMsg, "query failed", 0);

It would be helpful to know what the error message says.

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

Check to see that <cstdio> was included and not <stdio.h>

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

The functions you are seeking is Windows Hooks. Just include <windows.h> and you will get their prototypes, as well as declaration of BOOL and other win32 macros/defines.

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

Q1: The program does not do any integer math -- its all floats, and may floats can not be represented exactly. What makes you think there are any errors in the computations? Here are the results I got

Please enter the value of x1: 1
Please enter the value of y1: 1
Please enter the value of x2: 15
Please enter the value of y2: 6
Please enter the value of x3: 3
Please enter the value of y3: 11
Area1 is: 65
Area2 is: 65.0000152588
Area3 is: 65
Press any key to continue . . .

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

i want the answer for a program wap to accept data dere we have to count number of characters,words,lines
i am waiting for reply

We don't do homework. You do the work, You post the code, You ask questions about what You do not understand. We will help with that -- but We will not write the program for you.

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

Corrected function

int **allocarray(int P, int Q) {
  int i;
  int **a;
  //p = (int *)malloc(P*Q*sizeof(int));
  a = calloc(P,sizeof(int*));
  if (a == NULL) 
    {
    printf("Error allocating memory\n");
    return 0;
        }
  /* for row major storage */
  for (i = 0; i < P; i++) {
    a[i] = malloc(Q*sizeof(int));
    if (a[i] == NULL)
    {
       destroyArray(a, P);
        return 0;
    }
  }
return a;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In think this is what you want. Allocating pointer p is not necessary. To make a PXQ array you have to allocate Q integers for each row in P.

void destroyArray(int **a, int P)
{
   int i;
   for(i = 0; i < P; i++)
       free(a[i]);
   free(a);
}

int **allocarray(int P, int Q) {
  int i;
  int **a;
  a = calloc(P*sizeof(int*)); // typecast not necessary
  if (a == NULL) 
  {
    printf("Error allocating memory\n");
    return NULL; // no point continuing
  }
  /* for row major storage */
  for (i = 0; i < P; i++)
  {
    a[i] = malloc(Q*sizeof(int));
    if( a[i] == NULL)
    {
           destroyArray(a, P);
           return NULL;
    }
  return a;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know, but that sounds malicious to me.

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

My guess is that you are trying to create the table every time you run that program. Delete line 5 and try it again.

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

I'm in the market for a blu-ray drive on my HP computer. I've googled and found a few, rather expensive ones. All I want to do is play blu-ray movies with it -- don't way to bun them or use it to copy them.

Anyone have any knowledge about them other than what can be found by google?

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

allocate it

class MyClass
{
   // blabla
};

int main()
{
    MyClass* pClass = new MyClass;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thank you very much, so that mean I need to remove line 30, 38, 43.

Yes

Just tested and I give error message if I enter the day's more than 31 and month more that 12.

Good :) I see a small bug in the assert statement I posted. The last test should use <= operator, not just < so that the last day of the month will be considered value. day <= daysPerMonth[mon-1])

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

you have two options to trace that program

  1. Learn to use your compiler's debugger and step through the program one statement at a time so that you can see how it is executed.
  2. Put some print statements in that code.

>>What I also cannot figure out is where the swapping of characters a and t is done to output "hta"?
That's because the chracters are not swapped.

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

Welcome to 32-bit programming :) Read this article.

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

lines 74-80. Its not necessary to actually perform that check. Just subtract the two numbers and get their absolute value diff = abs(f - g);

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

The asserts on lines 30 and 38 will not work because the value of t is the julian date so it will equal the specified value in the assert statement only on the very first iteration of the loop.

you could do something like this on line 17 of the code you posted, and then don't use assert at all in the remainder of the code:

assert(mon > 0 && mon < 13 && day > 0 && day < daysPerMonth[mon-1]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do you need to ask us -- just run the program and find out for yourself what the output is.

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

>>class MergingLists : public list
AFAIK a template can not be used as a base class to non-template c++ class.

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

>>which statement is executed after returning from the recursive call.

Line 45, then the loop continues, but at that point the value of i is the value of length - because lines 39 and 40 advance i to the end of the output string before doing any recursion.

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

After closing the file on line 20 you need to clear fstream's error before opening it again. On line 21 add address.clear(); If that does not fix the problem then more than likely the file is not where you think it is. If it's not in the current working directory then you have to specify the full path to it.

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

Thanks everyone for your input,

As I am using XP there is a 4Gb physical memory limit and
I suspect this is restricting the application to ~2GB max.

I was completely unaware that this limit existed as most windows classes
appear to have been built with longs I figured since memory address registers
are dealing 100GB that this issue wasn't applicaible

The problem is you are probably compiling with a 32-bit compiler which produces code that has a 2 gig limit, even if you are running 64-bit operating system. Get a 64-bit compiler and that limitation will go away, although there will be another, but much larger, limit.

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

call clock() before the loop starts and again after the loop ends, then subtract the two times. When the program runs fast enough the difference might be 0. In that case, put the loops into a function and call that function 1,000 times.

clock_t t1, t2;
t1 = clock();
for(int i = 0; i < 1000; i++)
     RunLoops();
t2 = clock();
clock_t diff = t2 - t1;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only way that can be done is to rewrite the entire file. One way is to read everything into an array, or vector, or strings, then reopen the file for writing. Rewrite all the strings except the one you want to delete.

Since the lines contain other stuff you might want to use getline() as you originally posted. Then replace if(line == fruit) with this: if( line.find(fruit) != string::npos) >> while(file->getline(line,size) != NULL)
Recode that like this: while( getline(file,line) ) if you make line a std::string instead of char*

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

Yes I know char* can not just simply be typecast to wchar_t*. But if the program is compiled for UNICODE the string has to be converted to wchar_t*, which the _T macro will do as you posted. There is no need at all for the typecast.

This will work whether UNICODE or not (No need to specify the W at the end of LoadLibrary() either because that too is just a typedef for either A or W depending on UNICODE setting. LoadLibrary(_T("test.dll"));

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

>>myArray.reserve(size);
Delete that line because the push_back() method will just add more integers to the array. Let vector resize the array as needed.

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

glad you found a solution. You didn't say that the numbers could be floats.

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

why are you even using memcpy() -- what you want is strcpy(), not memcpy(). memcpy() is normally used to copy blopbs of binary data not standard null-terminated strings.

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

>>would anyone mind helping learn to thread?

What do you want to thread? A sewing needle? :) You should start another thread if you need to know how to use _pthreads to create threads. But first google for _pthread_create() to see what needs to be done.

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

First of all you don't want to use getline() to read a single word because getline() will read the entire line. It is better to use >> operator to read words like this:

std::string word;
std::string filename;
...
...
// open the ifstream (Note:  ifstream should NOT be declared as a pointer!)
// use ifstream instead of fstream for input-only streams
ifstream file(filename.c_str()); 
// read the file one word at a time
while( file >> word )
{
   if( word == fruit )
   {
         cout << "Found it!\n";
          break;
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
LoadLibrary((LPCTSTR)_T("test.dll"));

You need to also #include <tchar.h>

You posted the wrong typcast -- should have been LPWSTR, not LPCTSTR. But with _T macro the typecast is not even needed.

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

C programs can not use any of the c++ stuff, so if you are expecting a c function to call a c++ function which returns std::string, then forget it. The best you can hope for is that the c++ program returns const char*. Then you will have to declare that c++ function as extern "C" , which essentelly tells the c++ compiler to treat the function as a C function calling conventions, and not mangle the function name. That means the c++ function can not be a method of a class or an overloaded function.

Since you are doing that much recoding, it will probably be easier to just convert everything to c++ and not use any of the *.c files at all. If there are C functions that can be used without change then just copy/paste them into a *.cpp file.

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

What about the locations LoadLibrary tried? Is the file "test.dll" a library?

In this case, yes, all DLLs are considered libraries for the purpose of LoadLibrary(). That function name could probably have been better named as LoadDLL(), but it wasn't.

i think you should do it in this way.

Nice code and link, but the problem isn't with GetProcAddress(), as the op previously stated.

@Nicholas: If you do not specify the DLL's location then it must be either in the current working directory or in one of the directories in your PATH environment variable. If there are more than one copy of the DLL on your computer then I'd suggest you delete all but one of them so that your program doesn't pick up the wrong (possibly out-of-date) version (been there myself, and done that too.)

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

The best way to approach that problem is to use <vector>, not C-style arrays. vectors are arrays which will expand as needed to contain however may data objects you want to put into it. Just include <vector> and use std::vector<int> firstArray; . When you want to add an integer just call it's push_back method like this: firstArray.push_back(10); (or replace the 10 with an int variable).


Second-best approach is to use a pointer to the array, and reallocate it as needed (duplicating the efforts of the std::vector class): int* firstArray;

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

There are several ways to do it. One way is to parse the string one character at a time. Something like this (Note: This was not compiled or tested, so use it at your own risk).

This does not solve your entire problem -- it just gets the numeric data. Your program will have to do something else to extract the math operator '-', '+', '*' and '/'. If you understand the code I am posting here then extracting the math symbol should not be a problem for you.

char* GetInt(char* str, int& n)
{
    n = 0;
    // skip over all non-digit characters
    while(*str && !isdigit(*str) )
         ++str;
    // convert all digits to an integer
    while( *str && isdigit(*str) )
    {
         n = (n * 10) + *str - '0';
         ++str;
    }
    return str;
}

int main()
{
    char* str = "q23 - q3 (or q23-q3)";
    int x,y,z;
    str = GetInt(str,x);
    str = GetInt(str,y);
    str = GetInt(str,z);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Without seeing the rest of the code I can't tell you why those errors occur in the standard library time.h file. Post baseanimating.cpp (or just attach it if it is pretty large file)

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

>>Is it true that it really are to many buttoncontrols and that there aren“t any solution to this ?
No -- I lied :)

If all those buttons do is change the color of a rectangle somewhere on the screen you can do that without any buttons at all. Just capture the mouse click event, and change the rectangle under the mouse. You could also simulate a button click by calculating a hit test to see what button would have been pressed had there been a real button control there and acting accordingly.

For example you can set up an array of 200 RECT structures that have x,y coordinates along with hight and width. Given this info for each rectangle when a mouse is clicked test each RECT to see if the mouse's x/y coordinate lies within the boundries of the RECT. That is essentially what the os has to do with button controls.