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

It's actually pretty even -- 18 Republicans and 15 Demoncrats.

<M/> commented: ... you know what i mean -_- +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

fn is a pointe to a function. It is set on line 11 but never actually used for anything. That is what your compiler is warning you about -- you could just delete line 11 with no loss.

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

use your debugger and put a breakpoint on WM_CREATE. Since the window hasn't been created yet there can be no message box to show you.

cambalinho commented: thanks +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you are a kid, all teachers are like Einstein :)

Reverend Jim commented: Some are like Frank-einstein. +0
<M/> commented: Actually, most kids won't know Einstein +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The way I understand it, __inline__is an older version of the inline keyword -- it was an extension to some compilers. It's pretty much obolete nowdays except for older c89 compilers (link).

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

It's really not all that difficult - the standard inline keyword is SUGGESTION to the compiler to duplicate the function contents each time it appears in the program -- the compiler can coose to ignore inline if it wants to. The gcc extension _always_inline causes thee gcc to duplicate the function all the time, whether optimizing the program or not.

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

There are a number of ways that a valid Windows license may become invalid. One way is to install a new motherboard in the computer or make other significant hardware changes. I've had that happen to me a couple times. The telephone numberf Ummn referred to is in the error message on the screen and may change from country-to-country.

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

IMO the best solution is to not use std::string at all in MyClass but use a character array, which will ensure the string is written/read from the binary file without a problem.

class MyClass
{
   char str[126];
   // other objects
};

This solution is for writing data to new files, not for reading your existing data.

Jsplinter commented: Yes, thank you. That is what I will do in the future! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not just practice on your own computer?

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

That's because "%x" is an unsigned hex 32-bit integer on 32-bit compilers. See this article.

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

Posts contributed to the community immediately become the property of DaniWeb upon submission.

See this link

ddanbe commented: Thanks for the info AD +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, if your program is anything like the one below then the strings may not be anywhere in the file because std::string contains a pointer to where the string is located in memory, and writing out the class does not auto write out those strings. In this case you just lost all three weeks of work without any hope of recovery. Load the file into memory with a hex editor to verify whethere the actual text of the strings are in the file.

Also, run the program and you will see that sizeof(MyClass) is the same for all records in the file regardless of the length of the string.

#include <fstream>
#include <string>
#include <iostream>

using namespace std;

class MyClass
{
    int a, b, c;
    string s1;
    float d, e, f;
public:
    MyClass()
    {
        a = b = c = 0;
        d = e = f = 0.F;
    }
    void setstr(string s)
    {
        s1 = s;
    }


};


int main()
{
    MyClass c;
    string s;
    ofstream out("text.dat", ios::binary);
    for (int i = 0; i < 5; i++)
    {
        cout << "Enter string # " << i << '\n';
        getline(cin, s);
        c.setstr(s);
        cout << "sizeof(c) = " << sizeof(c) << '\n';
        out.write((char*) &c, sizeof(c));
    }

}

It is usually much easier to serialize c++ classes if you use char arrays instead of std::sting. This makes sizeof(MyClass) the same regardless of the length of the actual string within the array.

Jsplinter commented: Very clear example and excellent advice! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not according to this article.

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

unless MSDN says otherwise, controls don't work with them. You have to expand those yourself before sending text to the control.

cambalinho commented: thanks +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My lungs because can't live without them.

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

You're right, this doesn't really work

`while (getline(myfile, line, ','))`

because when the last numbe on the line is read getline() does not stop until it reaches the next comma. Your's is a much easier and safer solution.

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

If such complications arise for the process writing C libraries for use with MASM, I can only assume that the two were never intended to be mixed in such a way.

Incorrect. You just need to understand how all that fits together.

My instructor, however, maintains that there is a portability between C and Assembly,

He is correct. It's been my experience that you write the main part of the program in C and use assembly to optimize critical parts. That way let the C compiler figure out what all libraries has to be linked.

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

You're talking about MS-Windows, right? You can easily get the file info in a C program (or another language) by calling win32 api function FindFirstFile() and FindNextFile(). They both fill in a structure that you pass to the functions that contains all the data.

You can rename a file by calling rename()

I don't know where the info for the icons come from, never tried to change them. But most likely it's in the registry somewhere.

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

declaration of character arrays in C is like this:

char var1[] = "1F 19 03 04 09 18 10"

Or if you want a pointer instead of an array

char* var1 = "1F 19 03 04 09 18 10"

There are several ways to convert "1F190304091810" to "1F 19 03 04 09 18 10"
Since you have to later compare the 2-byte values, you might want to map them into an array

char values[7][3];

where
values[0] = "1F"
values[1] = "19"
etc.

To do that you will need a loop and a pointer to the original array, then copy bytes 2 at a time within the loop.

char original_char_array[] = "1F190304091810";
char* ptr = original_char_array;
for(i = 0; i < 7; i++)
{
   values[i][0] = *ptr++;
   values[i][1] = *ptr++;
   values[i][0] = '\0';
}   
tyranneo commented: I find it the most viable solution. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move the function starting on line 28 into a *.cpp file -- you can't put executable code in header files because the compiler will duplicate the code in each *.cpp file that uses the header file.

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

Tutorials only scratch the surface of what you need to know about c++ language. If you really want to get into c++ programming then you will want to buy a good c++ book, such as The C++ Programming Language 4th Edition. Here is a lengthy discussion about c++ books.

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

Then it would be this:

TabPage^ tabPage3 = gcnew System::Windows::Forms::TabPage();

I use VS2008.

Upgrade your compiler.

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

We don't do homework. You write code, you post the code, and you ask questions about what you don't understand. Show the work you have done and someone will help you finish it, but don't expect anyone to write it for you.

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

Before c++11 you would have to use an os-dependent function to create a thread, or use boost thread class. For exampe, in MS-Windows you could call the win32 api function CreateThread() (windows.h header file)

Install VC++ 2013 which supports std::thread. Or use lastest Code::Blocks with MinGW (GNU) compiler

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

variable named tau is a static variable, which means all instances of the class share the same value of tau. It retains only the last value that was assigned to it, regardless of which class instance assigned it. So if you initialize tau to be 10, then assigned 2, only the 2 will be retained.

smitsky commented: Thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have the word const in the wrong place

void Draw() const

See this tutorial

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

Here is a C# drag & drop from FileExplorer tutorial

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

line 35: where is the array of curr->action ever set to anything other than NULL?

Where is the value of max set (line 35) ?

line 37: wrong delete. Since curr is not an array (see line 8) then that should be just delete curr; But that's not possible either because you changed the memory location to which curr originally pointer (line 35). You need another temporary pointer to hold the original address of curr that was set on line 8 so that it can be deleted on line 35.

If the action array is ever allocated new memory then you need to delete those too.

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

The only other problem I see is the comma at the end of the last line which may or may not be a problem. Remove it and see if that fixes it. You might also shorten the names of each field -- long names may be very descriptive but can be a bitch to work with. Some databases may have a limit on the length of field names.

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

Check if the table already exists.

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

#define TICKS_PER_SECOND ((GetPeripheralClock()+128ull)/256ull

The compiler sees GetPeripheralClock() as a function call -- remove the ()

#define TICKS_PER_SECOND ((GetPeripheralClock+128ull)/256ull

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

that says nothing about not being able to use VT_EXPANDTABS with DT_SINGLELINE or DT_VCENTER. The link you posted is the same one I posted. If you want to use '\n' or '\r' then you have to parse it yourself and split the line at '\n'

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

Did you try DT_EXPANDTABS ?

DT_SINGLELINE
Displays text on a single line only. Carriage returns and line feeds do not break the line.

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

ut why the double don't accept integers?

It has to do with what the compiler pushes on the stack. Integers are 4 bytes on the stack while doubls are 8 bytes. You told va_arg that the parameters are doubles and va_args attempt to get 8 bytes off the stack.

arning: command line option '-std=c++11' is valid for C++/ObjC++ but not for C

Does that file have *.c extension or *.cpp extension.

cambalinho commented: thanks +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How were you able to post this thread if you are not registered?

I tried formatting my Windows from beginning.

You mean you really reformatted your hard drive? Why?

Tried registering to 10 different forums and same problem.

You mean you get the same problem on all 10 forums? Maybe it's your name, try a different name.

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

line 54 is sending 3 integers, not 3 doubles. Make them doubles and see if that solves the problem.

double a=average(3,10.0,50.0,6.0);

cambalinho commented: thanks for all +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the _vsntprintf() link isn't working

You're right -- I must have copied the wrong url into the clipboard.

but why use it? what means?

I don't use it. there may be a compiler setting to change the default to something else, but I'm not sure about that. That's the only reason I can think of to use CDECL.

cambalinho commented: thanks +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

_cdecl is the default calling convention for Micosoft Visual Studio. There is no need to explicitly use CDECL.

_vsntprintf() -- wrong. (link). How is _vsntprintf() supposed to know the size of the first parameter???

Please study a tutorial on variable arguments, then you will understand how that function is working. vsntprintf () is doing all the hard work of combining all the strings in the last parameters to that function.

cambalinho commented: thanks +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program appears to be retaining one of the last answers

1 10
1 10 20
100 200
100 200 125
201 210
201 210 125
900 1000
900 1000 174

The problem is that you need to reset maxCaseLen back to 1 after the scanf(), between lines 12 and 13.

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

your answer for 201 210 is 174, should be 89 according to the example input/output in the instructions.

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

Or change line 13 to this so that token has a pointer to unique memory:

token[i]=strdup(buff);

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

They can install pirated Window XP into thier computer.

Wrong. Ending support does not end Microsoft's copyright (link).

it is alright or not to install pirated Windows XP

Not. You could potentially be sued by Microsoft, fined and/or jailed for theft.

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

Done. Next problem.

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

can I cast the return type of malloc (void *) to another type ( Struct Switch *)

You can cast the return value of malloc() to anything you want, but that doesn't make any sense to allocate memory for sizeof(struct Switch) then assign it to Vector*.

I thought of changing the function newVector.

Looks like that will work. Just make sure that data does not get desroyed outside of the Vector class. For example

int* data = malloc(sizeof(int)*10);
Vector* = newVector(data,1000);
free(data); // this will invalidate the pointer stored in Vector
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is this the right way to call the newVector function for instance ?

No.

#include "Vector.h"


typedef struct tagSwitch
{
    int a, b;
} Switch;

int main(int argc, char* argv[])
{
    Switch* aSwitch = 0;
    Vector* NetRouters = newVector(aSwitch, sizeof(Switch*));
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have several syntax errors. Here are the corrections. Note that the return value of malloc() can't be typecase to something called data. In C language a typecase of void* return value is necessary (but it is in c++).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include  "Vector.h"

void FatalError(const char* msg)
{
    puts(msg);
    exit(1);
}

//action of setting a new vector
Vector* newVector(void *data, unsigned long elemsize)
{
    Vector* pvec = (Vector*) malloc(sizeof(Vector)); //memory space set
    if (pvec == NULL)
        FatalError("Malloc failed.\n");
    memset(pvec, 0, sizeof(Vector));

    pvec->reserve = 1024;
    pvec->capelems = pvec->reserve;
    pvec->elemsize = elemsize;
    pvec->elems = 0;

    pvec->mem = malloc(pvec->capelems * pvec->elemsize); //pvec->elemsize is the sizeof(data)
    if (pvec->mem == NULL)
        FatalError("Vector Malloc failed.\n");
    memset(pvec->mem, 0, sizeof(pvec->capelems * pvec->elemsize));
    return pvec;
}

//action of deleting a vector
void deleteVector(Vector* pvec)
{
    free(pvec->mem);
    free(pvec);
}

//action of extending a vector size
void resizeVector(Vector* pvec, void* data, unsigned long capacity)
{
    pvec->capelems = capacity;
    void* mem = malloc((pvec->capelems + pvec->reserve) * pvec->elemsize);
    memcpy(mem, pvec->mem, pvec->elems * pvec->elemsize); //copy characters from memory
    free(pvec->mem);
    pvec->mem = mem;
    pvec->capelems += pvec->reserve;
}

//action of pushing back an element to a vector
//Adds a new element at the end of the vector, after its current
//last element.The content of val is copied (or moved) to the new element
void push_backVector(Vector* pvec, void* data, unsigned long elemsize)
{
    assert(elemsize == pvec->elemsize); //check certain conditions at run time
    if (pvec->elems == pvec->capelems)
    {
        resizeVector(pvec, data, pvec->capelems);
    }
    memcpy(pvec->mem + (pvec->elems * pvec->elemsize), data, pvec->elemsize);
    pvec->elems++;
} …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

storedValue on line 13 is an object of each instance of the class. Each instance of intCell has it's own copy of storedValue. The objects on lines 34 and 40 are two different instances of the class, so they will not have the same copy of storedValue. If that is what you want (all instances have the same copy of storedValue) then you need to make storedValue a static member of the class.

class IntCell
    {
          public:
            IntCell() {} // <<<<<<<<<<<<<<<<<<<<<
            int read() const;
            void write( int x );
          private:
           static int storedValue; // <<<<<<<<<
    };

That will make storedValue just like any other global variable, so you will need to declare it as a global. Notice that you have to remove the initialization from the constructor so that the constructor doesn't destroy the current value when a new instance of the class is instatiated.

Somewhere near the beginning of the *.cpp file put this line:

int IntCell::storedValue = 0;

smitsky commented: Excellent advice as always! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, highlight the text you want to quote and press Ctrl+C (copy to clipboard)

Next, in your post where you want the text to appear first insert > character then press Ctrl+V (paste from clipboard)

Here are some links where you can find good coding style guides. There is no one-way to code so select what you find useful to you.

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

Yes you're right. My first few attempts I couldn't even get a Hello World program to work!

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

Your indent style is needing big improvement.

I'd hate to see his 1,000 line long program :)