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

In any case, I still prefer writing well-performing code regardless, even if it's just for the elegance of it.

Yes, I agree. Just because programs can be bigger and run faster today then years past doesn't mean programmers can write sloppy, bloated, and redundent code.

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

I couldn't find much about it on their web site, but if the libraries have *.a or *.lib extension then you just link with it just like linking with any other library.

I just installed the MS-Windows version and all the DLLs and *.lib files are in <install folder>/bin folder. I'm not sure whether Code::Blocks can use them because CB normally uses *.a libraries, just like it's *nix counterpart.

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

Tolerable -4C (24F) right now -- expecting lots of snow Saturday night, largest snowstorm in over 15 years. Weather casters have said that before but it went around us and we didn't get a snowflake. We'll see if that happens again.

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

That "performance doesn't matter because hardware is so good now" argument from the 90s has largely been dispelled in the latest years (5-10 years) for those reasons I just mentioned.

For servers applications (e.g. DaniWeb) that may be true, but I doubt for desktop apps where there is only one person using the whole computer.

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

The Lone Ranger -- good movie, but nothing like the original tv series from the 1950s.

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

I think addressof returns the offset of the function from the beginning of the executable, not the absolute address in memory. Here are some invalid uses of the AddressOf operator.

The function which I want to call belongs to a VB6 executable,

I thought you were talking about a DLL written in VB. LoadLibrary() can't be used to load a *.exe file into the address space of the calling process.

Here are three ways to inject your code into another process.

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

burrr

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

Here is why English is to hard to learn.

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

What makes you think the function is loaded at 0x00401B90 ??? Under MS-Windows you never know where a dll or program is loaded and any attempt to guess will most likely be wrong. Your c or c++ program needs to call GetProcAddress() after calling LoadLibrary() in order to get the address.

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

You just proved my point -- too many chiefs and too few indians (native americans, not referring to people from India). Where I live people who get a Ph.D. are overqualified and have difficult time finding jobs, other than flipping hamburgers at McDonalds.

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

undefined reference to `WinMain@16'

That normally means you are compiling a MS-Windows GUI program but use main() instead of WinMain(). But I think you need to post code and the makefile so it can be tested. Does the esample program here compile correctly?

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

See my answer in your other post. Please, do not double post the same question.

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

strtok() will destroy the original character array by enbedding '\0' each time strtok() is called. So if you need the original character array then the function that calls strtok() first needs to duplicate the string.

#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>


 typedef struct dict_word *word;
 typedef struct node *Node;
 typedef struct double_linked_list *DLL;




 struct dict_word
 {
char words[100];
int year[10];
char eng_synonyms[100];
char heb_synonyms[100];
 };


 struct node
 {
word data;
Node *next;
Node *previous;
 };


 struct double_linked_list
 {
Node *head;
Node *last;
 };


 char *split(char words[100])
 {
int i;
char* words_dup = malloc(strlen(words)+1);
strcpy(words_dup,words);
char *word=strtok(words, "_#_");
char *year=strtok(NULL, "_#_");;  // assigning NULL for previousely where it left off
char *definition=strtok(NULL,"_#_");
char *synonyms=strtok(NULL,"_#_");

i=atoi(year);

printf("%s\n", word);
printf("%i\n",i);
printf("%s\n", definition);
printf("%s\n", synonyms);

// now restore words
strcpy(words,words_dup);
free(words_dup);
return 0;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Does that mean we have too many Ph.D. researchers???

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

The only time I have found recursion useful is when transversing the file system, such as in this code snippet. Otherwise I try to avoid it, mainly because many years ago recursion was just too expensive in terms of memory and time. I know those aren't as critical any more but old habits don't go away easily. I see no reason to spend time teaching something that is rarely, if ever, used. There is currently a huge debate here in US about teaching cursive in grade school because people don't use it any more. Thanks to the computer age cursive will one day be a lost art.

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

But it is, saying that a private var (d_lenght) in shape2D cannot be accessed because is private.

I think you misunderstood the error message. It means that Shape3D can't access private members of the base class. It's complaining about the line cin >> d_height; that appears in shape3D::set_dimensions().

Can you please be more explicit with set and get functions?

Yes, you explained it yourself perfectly, although normally they would be written as inline methods, but the way you have them is ok too.

class a
{
    public:
        a();
        virtual ~a();
        void set_value(int x) {y=x;}
        int get_value() {return y;}
    private:
        int y;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is this program for school or for a job? You didn't answer my last question. Here is one way to do it. extract() retrieves all the digits from the string returned by strtok(), and stops converting when it encounters anything else but a digit or '.'. You could easily modify this to store the data in whatever arrays you want to produce start and end values you need.

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>


char* extract(char* p)
{
    int i = 0;
    char buf[40] = { 0 };
    while (*p && (isdigit(*p) || *p == '.') )
    {
        buf[i++] = *p;
        ++p;
    }
    buf[i] = '\0';
    printf("%s\n", buf);
    return p;

}

int main()
{
    char str [] = "A1.1*7.1&9.1&11.1/";
    char *ptr = strtok(str, "&");
    while (ptr != NULL)
    {
        char* p = ptr;
        while (!isdigit(*p))
            ++p;

        p = extract(p);
        if (*p == '*')
            p = extract(++p);
        ptr = strtok(NULL, "&");
    }


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

Oops!

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

Yellow Submarine

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

I actually wrote this program today just for fun -- as it turned out I wrote a function that generated a random char between two decimal values, then called it twice to generate 2 digits, twice to get two upper case characters, twice to get two lower case characers, and once to get a symbol. Then I called it 3 more times to generate any random printable character. Finally, call std::random_shuffle() to mix them all up.

But, I'm not about to post the code because that wouldn't help the OP at all to learn how to do it himself.

and I need to write a dictionary file.

I have no idea what that means. What is the file supposed to contain?

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

Granted -- but the planet just ran out of gas so the gas prices are 0.

I wish I was a mountain climber

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

It doesn't really matter where you put the space in the syntax, the compiler doesn't care. The examples you posted are all acceptable and correct. It's only a matter of programming style -- however you wish to do it.

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

I don't understand why it works with private vars if I don't modify the methods and why should I use protected in the other case.

private: means the derived class cannot access the variable -- if the defived class doesn't attempt to access the private member then there is no problem or error. There's a couple ways you can handle that.

  • Change the variables from private to protected
  • In the base class add get and set functions
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Then you did something wrong. This works perfectly

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

int main()
{
    int vowelcounter = 0;
    char * tokenPtr;
    char myarray [] = "My name is Faraz Saleem Rafai";
    char check [] = "aeiou";
    int length = 0;
    int origlength = strlen(myarray);
    // display all the vowels.  Your program doesn't need this part, 
    // it's here only to verif the results are right or wrong.
    for (int i = 0; myarray[i] != 0; i++)
    {
        myarray[i] = tolower(myarray[i]);
        if (strchr(check, myarray[i]) )
            cout << myarray[i];
    }
    cout << '\n';

    tokenPtr = strtok(myarray, check);
    while (tokenPtr != NULL)
    {
        length += strlen(tokenPtr);
        tokenPtr = strtok(NULL, check);
    }
    cout << "orig length: " << origlength << " numvowels = " << origlength - length << '\n';
    return 0;



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

actually It can be really interesting if you tell us the story of your life

One word -- "boring".

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

I'm with the Reverend -- I'm 70 and still have all my parts too -- just lucky after smoking for 50 years (stopped 13 years ago). I've already lived 10 years longer than either of my parents.

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

Wow - what a big mess.

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

Please attach the data file you are using or the program you used to generate it.

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

That's why I said you have to change the coordinates of SetRect() so that the pixel location is within the coordinates of the static control. You might want to study this about mapping modes, unless you have already done that.

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

this changes the colors, but the text is in the center of the window. I don't know if that is where the control is located or not. I made the background color yellow so that I could see that it is doing something. You will probably have to change the coordinates of SetRec() to something else so that it's within the boundries of your static control.

        case WM_PAINT:
        {

                         PAINTSTRUCT ps;
                         HDC hdc = BeginPaint(inst->hwnd, &ps);
                         RECT textRect;
                         SetBkColor(hdc, RGB(233, 189, 174));
                         SetRect(&textRect, 10, 210, 200, 200);
                         DrawText(hdc, TEXT("Hello"), -1, &textRect, DT_CENTER | DT_NOCLIP);
                         EndPaint(inst->hwnd, &ps);
        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry, I don't think I can help you -- your code has a lot of constructs that are probably from c++11 -- I haven't studied that.

Example: event(NotResize) = [](){; }; I have no clue what that's doing. I know event is a macro, but the rest of that line looks like greek to me.

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

Woke up to light snow this morning, we got about an inch on the ground. I suppose you people in Canada find us sothern Americans somewhat amusing that we close all the schools at the first snow flake :)

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

sorry, we are 'in same page'?

Probably not. When I run your original code snippet it put "Hello" in the window's title bar. I'll help work on it after awhile, but not promising any useful results.

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

First, you need to use rand() (click me) to generate random characters that can be used in passwords. Do this in a loop. Each time rand() is called check it's return value to find out what kind of character it returned (upper case, lower case, digit, or some other symbol)

If you look at any ascii table, such as this one you will see that all printable characters and symbols have decimal values between 33 and 126 (the space (decimal 32) is also considered printable but not useful for your program). So in order to generate a value between 33 and 126 the math is like this:

int ch = 33 + (rand() % 126)

Now, each time a value is generated search the array of password characters already generated to see if the new value is already in the array. If it is not in the array then add it. If the character is already in the array then ignore it and continue the loop to generate another random character. Since we don't know how many times this loop will repeat itself its best to use a while loop then break out only after the required number of characters have been validated.

Don't attempt to write all that code at one time, you will most likely just get confused if you do. Write a few lines, then compile and test that it works correctly. After that repeat until the program is done.

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

SetWindowText

Changes the text of the specified window's title bar (if it has one).

And another link

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

When there are more than 3 or 4 parameters it's better to create a structure or class to hold them all so that the function itself has only one parameter. It's a lot easier to read and understand that way.

why in the voucher print function its not displaying cost near hire cost

You need to put some print statements inside that function to display the values of all those parameters. Or better yet, learn to use your compiler's debugger.

Note: function AmountDay() doesn't work right either. Regardless of whether daysamount[i] is a digit or not the function returns on the first iteration of the loop. Also, daysamount is a string array, not an int array, so the second test to see if the value of daysamount[i] < 1 is not a valid test because daysamount[i] is a character, not an integer.

Here's how that function should work

bool AmountDay(string daysamount)
{//function checking the string taken in is digit
    for (int i = 0; i < daysamount.length(); i++)
    {
        if (!isdigit(daysamount[i]) || daysamount[i] == '0')
        {
            return false;
        }
    }
    return true;
}

AddDriver() also has a problem -- The function needs to return a value before it exits at the bottom of the function.

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

From everthing I read the color of the text in window titlebar can't be changed without using SetSysColors(). There is an example program at the end of that link, but you mighgt want to google around for other examples.

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

Note: I'm working up an example of your question.

or the hwnd or even the hdc aren't correct

that is the case one of the parameters to WinProc() is the HWND of the window that is to be processed. Not a good idea to keep track of it in your own class as it may change every time WinProc() is called. All controls are also considered windows so that will each have their own unique HWND value and WinProc() is called to handle them.

why i can't build a function(inside the class) for change it directly?

What function do you mean? WinProc() can be a static method of a class or just a global function, it must be a global function with that name, just like main() is not part of any class.

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

What is "planteas"?

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

as my professor always said that in order to create a program you must know first the output before you create a code ...

Yes, I would agree with your professor. How can you write a program to do something if you don't know what the program is supposed to do? You can't bake a pie if you don't know what kind of pie you want.

a= (char *) malloc(30 * sizeof(char));

In C language it is not necessary to typecase the return value of malloc() or any other function that returns void* value. But --- follow your instructors requirement for that becaue typecasting the return value from malloc() is optional.
a= malloc(30 * sizeof(char));

Another problem with the above is that sizeof(char) is not needed because sizeof(char) is guarenteed to always be 1.

a= malloc(30);

With such small amount of memory I question the reason for using malloc at all -- why not just make the array static?
char a[30];

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

do you mean an in-memory array of integers? such as int myarray[25]; ? Or are you talking about records in a file or sql database?

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

Could you explain me why in every function you use something like: struct item*

Yes, because that parameter is the head of the linked list to be used. How else do you think those functions are going to know where the top of the linked list is, and which linked list the function is supposed to use?

what does it change, and is there need for strcpy function in AddItem

AddItem creages a new node of type struct item, copies the value of item_name into the structure, and finally inserts the new node at the tail end of the linked list.

as I'm not that familiar with it.

You should already be familiar with strcpy() function, its one of the very basic string functions you learn. Since you are studying linked lists you most likely have already learned about strcpy(). If not, look it up in your textbook or google for it online.

Also would like to know why in function AddItem there's struct item** head while function FindTail has struct item* head .

Because AddItem() is going to change the caller's linked list, while the other functions such as FindTail() does not. The only way AddItem can change the value of the pointer passed by the calling function is to pass a pointer to the original pointer. I know, pointers can get confusing, but that will become clearer after you study and test it yourself.

Your thoughts at the end of …

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

You need to instantiate a public or static brush so that the colors don't disappear as soon as that function ends.

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

seems like normal linked list for me.

Yes -- what you want is just two nested normal linked lists.

Once you understand simple linked list it is just slightly more complicated to do nested linked lists. I would do it like this: The last function AddItem() shows how to allocate memory for the item linked list.

    struct item{
    char item_name[30];
    struct item *next;
    }

struct client{
    char name[30];
    char last_name[30];
    struct item *d;
    struct client *next;
}


struct client* FindClient(struct client* head, const char* name)
{
    while(head->next != NULL)
    {
        if( strcmp(head->name,name) == 0)
        {
          return head;
        }
        head = head->next;
    }
    return NULL;
}


struct item* FindItem(struct item* head, const char* item_name)
{
    while(head->next != NULL)
    {
        if( strcmp(head->item_name,item_named) == 0)
            return head;
    }
    return NULL;
}

struct item* FindTail(struct item* head)
{
    while( head->next != NULL)
       head = head->next;
    return head;    
}

struct item* AddItem(struct item** head, const char* item_name)
{
    struct item* newnode = malloc(sizeof(struct item));
    newnode->next = NULL;
    strcpy(newnode->item_name,item_name);
    if( *head == NULL)
    {
        *head = newnode;        
    }
    else
    {
        strict item* node = FindTail(*head);
        node->next = newnode;
    }
    return newnode;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Were those two structures given to you or can you make them up yourself?

There are two linked lists -- Client and within each client node is a Items linked list.

To add a new client node you have to search the Client linked list to see if it is already there. If not, then add a new Client node to the end of the Client linked list.

To add a new Items node to a Client node, first find the Client node, as above. Once found, search it's Items linked list to make sure there isn't already an Items node in the list. If not, then add a new Items node to the tail of the Items linked list.

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

Oh Damn, now I have to change all my passwords. Happy New Year! I just had a great evening with my family, lots of quality time, hoping you did too.

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

Burrrrr! You can keep all that cold up there, I don't want it down here. It's only a little chilly here today, almost don't need a coat outdoors.

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

I really miss the old New Year parties from the 1950s and 1960s on TV -- they really new hold to throw parties!

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

Granted, but the 3d hand is completly useless.

I wish I was a car.