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

Just convert the int to a string and add "0x" to the beginning of the string

int serial = 40000359;
char result[20];
sprintf(result,"0x%d", serial);

Or if you want to use only c++

#include <sstream> 
#include <string>
#include <iostream>

int main()
{
   int serial = 40000359;
   std::string result;
   std::stringstream str;
   str << "0x" << serial;
   str >> result;
   std::cout << result << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those are not pointers. Here is how you make an array of pointers to strings. With this, your program has only one variable name to contend with, not 12. char *no[]={"1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th"}; Once you enter a value 1-12 you can easily display the string using that index value, but first you have to convert it to a value 0-11 because the first element of any array is 0, not 1. Then you don't need that switch statement at all. Below is the only line you need. cout<<"It's the "<<no[num-1]<<" month and it's "<<months[num-1]<<"."<<endl;

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

>>but its also opening the source code of that exe file
The OP is most likely wrong about that. *.exe programs don't need the source code for its own program. When I compile Hello.cpp to create Hello.exe the *.exe file doesn't need Hello.cpp. It might need some other shared libraries or DLLs, but that's a different problem.

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

If you want to customize drawing of the edit control then you will have to cusclass it. I already gave you a link to one way of doing that. You can find other ones on www.codeproject.com, which has the largest repository of MS-Windows code on the internet.

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

just like I said

int a = 40;
int b = 3;
double intpart = 0;
double result = (double)a/b;
double fract = modf(result,&intpart);
int result = (int)fract*10; // convert 0.3333... to just 3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Then just use normal division (either float or double). After doing the divion you can call modf() to split the variable into integer and fractional parts. Certainly a lot easier to just use % operator.

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

for the pointers you need just include <windows.h> There's nothing magical about it -- it's just the standard run-of-the-mill char pointer. Whether its char* or wchar_t* depends on whether you are compiling your program for UNICODE or not. If you don't need UNICODE for non-English languages then turn it off.

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

In the loop i+j requires the addition of i and j in order to resolve the index into pWord. That takes unnecessary clock cycles. Just simply continue to use the i counter that already contains the value that is needed in the loop.

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

Or to avoid costly addition operations

for (j = 0; pTemp[j] != '\0'; j++,i++)
      pWord[i] = pTemp[j];
   pWord[i] = '\0';
vinitmittal2008 commented: useful info! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How do I expand and collapse this? I've tried the arrows to the upper right corner and nothing happens.

Just hit the Post Reply button

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

The mod operator is simply the remainder after division. For example, 4%2 is 0 because the remainder after 4/2 is 0. The mod operator works only on integers, not floats or doubles. There is no code to give you because that's all it is -- a simple 5th grade math operation.

[edit]And what ^^^ said.[/edit]

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

I once crashed the entire Unix operating system with a one-line statement: int* ptr = malloc(sizeof(int) * (MAX_INT_SIZE+1)); MS-Windows operating system today is pretty stable and won't allow a single program to crash the entire os. I haven't seen such a crash in quite a few years.

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

The best and simplest way to keep data private is to put the data on a flash drive (or usb drive) so that you can remove it from the computer when you are not working with it.

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

limits.h is part of your compiler. Just look in your compiler install folder.

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

subclassing is a little bit like deriving another class from a base class. Assume you have a class named Animal and you want to make a class called Cat. In terms of MS-Windows controls that would be called subclassing and is done in C, not C++ (although you can use it in your c++ program as long as you use standard C syntax.)

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

Sadly, FolderSafe is not compatible with 64-bit Windows 7. I was going to install it on my computer to see how good or bad it is but it doesn't work.

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

max values are declared in limits.h

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

No -- he is saying he wants to hide the program from everyone except himself -- sounds pretty malicious to me. It's not even possible on MS-Windows because anyone with Admin privaledges can view every program in the system. Programs can not be hidden from Admins or antivirus programs, and for good reason.

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

>>because the compiler prints the
Don't blaim the compiler for the code you wrote :) The logic of your program is flawed.

scanf("%c" expects you to enter an alphabetic character, such as 'D'. The switch statement is checking for numeric data, such as 0, 1, 2, ... Since you used scanf( with %c that switch statement must check for the numeric values of the character, such as '0', '1', '2' etc. Note that using < and > doesn't mean much with that because, if you look at any ascii char you will see that there are NO characters < 0 and they are all > 0. Finallly, its ot possible to eter a negative value with %c.

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

There is a list of the top 100 members that is probably more useful than the full list because the top 100 members will include most, if not all, the active members who post here. See the "Top Members By Rank" link the very top of the page.

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

When you compile a program the compiler generates the executable program that is usually self-contained except maybe for a few operating system shared libraries and DLLs. You can move the executable program any where you wish on your computer and it will normally run without problems. The source files (*.cpp and *.h) are not needed after they have been compiled. The compiler puts the exe file in the same folder as the source files only for your convenience.

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

Customizing the edit control can get pretty complicated. Here's one thread on that topic. Here are a few others.

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

You need to find out what PVOID is defined to be. If it's not defined to be anything, such as define PVOID then the compiler will produce C4430. If you don't know what C4430 error is then look it up with google.

>>HAPTIK_DLL_IMPORT_EXPORT
Your program need to define that symble to be either dllspec(__import) or dllspec(__export) depending on whethere you are declaring it in a DLL or the application program that uses the DLL. Just putting a semicolon after it like you did is not the correct solution.

claudiordgz commented: Awesome response +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could do this

class something
{
   public:
      char attribute1[25];
      char attribute2[25];
      donkey(char* a, char* b)
      {
          strcpy(attribute1,a);
          strcpy(attribute2,b);
      }
      donkey(){}
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

google is you friend, learn to use it. Click here

geojia commented: Haha, Very NICE! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are talking about an int or float array, the answer is no because there is no such value as infinity. Integers have maximum values, which are declared in limits.h header file.

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

>>if no one answers my thread i cannot get to it again

See that purple ribbon at the bottom of the screen? It contains several links -- one of them is "Threads I've Posted In" and another "Threads I've Started". Just click "Threads I've Started" and DaniWeb will show you links to all the threads you have created, whether anyone has posted in them or not. Can't get much smipler than that friend.

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

you used the wrong index value in this loop

cout<<"enter the elements of the array";
                        for(int i=0; i<y; i++) // <<< this should be < y, not <= y
                        {
                           cin>>bector[i]; // <<<< this one
                        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 5: float vector[];
arrays are declared with the star, like this: float* vector; In the constructor you need to allocate memory for the array vector = new float[x]; Change the name vector to something else because vector is the name of a c++ class declared in <vector> header file.

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

Death of PC? Well, probably in 100 or so years from now after something better has been invented and accepted in business to replace the PC.

Agapelove68 commented: Thank you for the reassurance! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't really matter which one you take first. c++ is an older language but also the most widely used language of the two. You will never go wrong learning both languages.

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

Output the value of N (which is the i loop counter) before each iteration of the loop in main(). That way when the program crashes due to too big N you will know its value.

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

Hey Perry 31,
I recently was reading up on white space rules for C. From what I gathered, tokens such as variable names, function names, variable data type names, other important words in the language, when in contact with operators are naturally separated.

Because of the phenomenon being true that int *var; is syntactically equivalent to int* var;, int*var;, and int<any number spaces>*<any number spaces>var;,I would suffice it to say that the pointer is considered an operator, which would explain why the organization does not and will never have an effect on the functionality when you, I, or anyone else are programming.

In otherwords, to boil down that long-winded post, the answer is like I said before, There is no difference.

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

Whether you use Show() or ShowDialog() depends on whether you want a modeless or model dialog window. Below code works for model dialogs. First close Form1 then show Form2. After Form2 is closed you have to show Form1 to make it visible again.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
				 Form2 ^form2 = gcnew Form2();
				Form1->Close();
				form2->ShowDialog();
				Form1->ShowDialog();
		 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>is there's anyway to output anything when the computer stops (when it ran's out of stacks )

Nope -- your program is trashed at that point. Post the function you are attempting to write, and tell us the compiler and operting system.

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

There is no difference -- just programmer preference.

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

>>sizeof(uint16_t) * 16
Wrong. All that gives you is the number of bits (not bytes) in one integer. what you want is the size of one of the arrays, such as ARRAYSIZE*sizeof(uint16_t) >> do i need to use strcpy
No. strcpy() works on strings of text data, not numeric data.

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

>>I am not expert like you. I am learning just less than 1.5months whether you believe or not it is up to you.
I made no mention of that, so that statement is not relevant to the problem or the solution. Sorry that you thought my post was not positive -- I wrote nothing that was ciritial of you. I was just trying to help you improve your program and point out problems. If you can't take the heat then get out of the kitchen because you will always find people who critique your programs. If you can't take that then stop programming and take up basket weaving.


>>you can not put executable code .. are you sure ?
Yes, I am absolutely sure, afterall I've been at this enough to know (about 25 years now). If you split up your program so that it uses two or more *.cpp files and put that header file in each one, then the compiler will complain about duplicate functions. Learn to do it correctly right now so that you do it right when the time comes for you to write more complex programs.

>>i use getch() for freezing the screen to see the result. just way of writing
Yes I know -- but what I said doesn't change that. cin.get() will normally do the same thing but in c++ ways. Both cin.get() and getch() will fail to do what you want if there is already …

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

in square.h -- lines 13-17. You can't put executable code in header files like that. If the intent is to make them inline, then do it like you did on line 9, what is void set_values(int a) {x = a;}; square.cpp: delete conio.h and replace getch() with cin.get(). No point using non-portable C code in a c++ program when its not necessary. It does nothing more than make your code look bad to other people (like your instructor).

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

Another way to do it is to allocate one large block of memory that is x*y*z*sizeof(int) bytes, then calculate the index into it yourself. Freeing up the array is very easy -- since there is only one pointer there will be only one call to free().

int* allocMatrix(int x,int y,int z)
{
    int* ay = (int *)malloc(x*y*z*sizeof(int));
    memset(ay,0,x*y*z*sizeof(int));
    return ay;
}

void disp(int* ay,int x,int y,int z)
{
    int i,j,k;
    for(i = 0; i < x; i++)
    {
        for(j = 0; j < y; j++)
        {
            for(k = 0; k < z; k++)
            {
                int spot = (i*y*z)+(j*z)+k;
                printf("ay[%d][%d][%d] = %d\n",i,j,k,ay[spot]);
            }
        }
    }

}

int main()
{
    int i,j,k,m;
    int x = 5;
    int y = 3;
    int z = 4;
    int* ay = allocMatrix(x,y,z);
    int spot = 0;

    for(i = m = 0; i < x; i++)
    {
        for(j = 0; j < y; j++)
        {
            for(k = 0; k < z; k++)
            {
                int spot = (i*y*z)+(j*z)+k;
                ay[spot] = m++;
            }
        }
    }
    disp(ay,x,y,z);
    free(ay);
}
MarounMaroun commented: Helpful! Thanks Ancient.. always here to help. +1
mitrmkar commented: Effective +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void Free(array *free)
Change the variable name from free to something else because free is a C standard function name, and the compiler will get confused.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
struct matrix* InitMatrix(int x, int y, int z)
{
   struct matrix* m = malloc(sizeof(struct matrix));
   // initialize the structures elements

   <snip>
   return m;
}

Free it in reverse orderof allocating it.

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

>> wanted to edit and correct the post but can't figure out how.

You only have 30 minutes to make changes. After that you are just SOL ("Sadly Outta Luck" (polite form) for anyone who doesn't know that that means).

Your code snippet is in error. char a; should be char* a;

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

You forgot to include <string> header file.

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

line 24: using an uninitialized pointer ptr You have to allocate memory for it before it can be used.

line 57: child is NOT an array of pointers to structures, but an array of structures. There is a difference. In the structure you need to declare child like this: struct node** child; Notice it has two stars, not one. Then in create() method, allocate the array of pointers like this: child = new struct node*[size];

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

Here is a simple example. The only reason it includes windows.h is because it uses the win32 api function Sleep() It will become more complicated if each of the threads must access the same global variable or common function. In that cast the threads have to be synchronized to avoid clashes while reading or writing at the same time.

#include <process.h>    /* _beginthread, _endthread */
#include <Windows.h>
#include <iostream>
using std::cout;

void MyThread( void *dummy );


int main()
{
    for(int i = 0; i < 5; i++)
    {
        _beginthread( MyThread, 0, (void *) (&i)  );

        /* Wait one second between loops. */
        Sleep( 1000L );
    }
}

void MyThread( void *param )
{
    int i = *(int *)param;
    cout << "Hello World from " << i << '\n';
}
cwarn23 commented: Great code in speedy time :=]] +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you don't already have MinGW then download codeblocks-10.05mingw-setup.exe

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

vc++ 2010 Express
Code::Blocks

google for them and you will find the links

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

Whether you use VB or PureBasic will depend on what you want to do with them. I know virtually nothing about PB except what I just read on their web site VB 2010 integrates well with all the other programming languages available in Visual Studio, that is, you can mix and match all the languages in the same program if you want to. There are many things that can be easily done in VB that are very difficult in other languages, such as providing Office solutions. But if you don't need all those whistles and bells then BP may be the better solution, and at 79 Euros its a lot less expensive too than the Professional edition of Visual Studio.

One advantage of PB is that the source code is portable to other platforms. VS is not portable.