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

unless you are sending a private message (one that you make up yourself) you can't control the value of lparam parameter. The easiest way to get a ponter to a specic instance of a class is to save the hwnd value in the class instance when it is first create, create a vector (or array) of class instances so that you can search the array for hwnd inside WinProc function. That's pretty much how Microsoft implemented MFC classes.

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

All messages are sent to the WinProc() procedure -- the first parameter to that function tells you which hWnd the message is for. In the case of wm_create the message is sent before the window becomes visible.

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

send it a text on your iphone?

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

cin >> buffer will auto stop getting keys from the keybord when cin counters the first white apace (space, tab or '\n'). Buffer will never contain any of those white space characters, so your loop on line 13 ill never find one.

If you want buffer to include all white spaces too, then call getline() instead of sin.

cin.getlne(buffer, sizeof(buffer)); But here too buffer will not contain the '\n' characters.

strlen(buffer) will return the length of the string in buffer.

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

might be gcc extension

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

Is this what you mean?

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

maybe something like this: Replacing the * with your own criteria

IF EXITS(select \* from tablename where <clause>)
THEN
   ' increment counter
ELSE
   ' insert new row
END IF
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, you are right -- line 2 jut prints a literal string.

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

line 2: what do you expect prinitf() will display? first is just an ininitiaolized array of random caracters which may or may not contain '\0' which printf() looks for to find the end of the array.

line 4: what will happen if I enter more than 15 characters on line 3? Answer: the program will crash because memcpy will copy the last few characters outside the bounds of the array.

line 5: too few parameters to printf().

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

line 11. sizeof a pointer always returns 4 on 32-bit compilers. There is no way for the compiler to determine the length of the data to which the pointer addresses.

Also about that same line and line 18. line 18 creates a pointer to a 1-byte string, yet on line 11 you are attempting to copy more than 1 byte to that memory. This is guaranteed to crash the program.

How do I fix it?

        int EncryptData(char *data_source, char *data_cipher, size_t sizeofdata)
        {
            char *tmp_data;
            long long int digit;
            tmp_data = new char[sizeofdata];

            /*
                Do some calculations here with some data and then store it in tmp_data.
            */

            memcpy(data_cipher, tmp_data, sizeofdata);
            delete[] tmp_data;
        }

// char* dest
int main()
{
    char dest[255] = {0};
    encryption.EncryptData("Hello world", dest, strlen("Hello world")+1);

        for(int i = 0; i < strlen(dest); i++)
        std::cout << dest[i];
}
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

where did you get sdl.h from?

example868 commented: it is an api +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move line 27 down to line 38 because you are throwing out the first token in the string.

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

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

The actual executable code for printf is contained in a library. I don't know which one it is for Turbo C. You may have to link your assembly program with several standard C libraries because printf may call functions in other libraries, which in turn call more functions in some more libraries. When you write a plain C program the compiler already knows about all those libraries and produces the correct link statements for you. With MASM, and other assemblers, you are on your own.

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

Why why why?

Because you also have to link with standard C small libraries that are in Turbo C install folders.

In your assembly code you can delete lines 16 and 17 because those two registers are not being used by your program.

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

Did you also use the small memory model with Turbo C?

When you linked the assembled code did you tell the linker to also use the *.lib file along with the *.obj file geenrated by masm?

If you did all that then I suspect there are linking problems between masm (Microsoft) and Turbo C++ (Borland) object files. In that case you will need to replace MASM with TASM (Borland assembler)

Also, ask your instructor what compiler you are supposed to use with MASM. There is an old Microsoft C comiler, but AFAIK it is not free.

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

Is that in response to a program you wrote? What compiler did you use? there are many ways to figure out where the problem lies -- one way is to put a bunch of print statements everywhere so that you can see where the program stopped when the error message appears. Another way is t0 learn how your compiler's debugger works.

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

I guess I misunderstood the assignment. To me, "sum up the vectors" means c[0] = sum(a) + sum(b)

Sorry, I can't test your program because I'm using MS-Windows and pthread.h is not supported there. c++11 standards supports threads directly now so you don't need pthreads.h or associated library. If you are using gcc compiler then the latest version contains support for c++11 standards.

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

The issue is that I don't need to have same number of pairs,

Not really a problem. In my previous example if there are only 5 pairs then make the other 2 empty NULL strings.

   values[5][0] = '\0';
   values[6][0] = '\0';

'm lost when I need to extract the elements 2by2.

It doesn't matter if you dynamically allocate the memory for the original strings or not, extracting 2b2 is the same as what I posted before.

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

It seems the two threads are overlapping the arrays. The first thread should add elements 0-4 and the second thread should add elements 5-9. And array C should only have 2 elements, not 10.

The loop on line 10 should run only 5 times, not 10 times because each thread is summing only 1/2 the number of elements in each array.

The last parameter on line 40 would also be incorrect. When i == 2 the last parameter should be 5, not 2 so that sum() starts summing the two arrays at element #5, not element #2.

Finally, why are the three arrays pointers and memory allocated at runtime? That is ok for huge arrays, but quite a waste of time/memory for small arrays. Lines 6-8 could simply be this:

const int N = 10;
const int n=2;
int a[N];
int b[N];
int c[n];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also, shouldn't it be
add sp, 8

No, because bx and dx are both 2-byte (16-bit) integers. ebx and edx are 32-bit (4 byte) integers.

MASM I am using was provided by our Instructor; wouldnt he have considered the choice of assembler

Maybe your instructor wants you to use a 16-bit C compiler. I don't know if Turbo C will produce the right *.lib files or not. MASM was produced by Microsoft in the 1980s to assemble MS-DOS 16-bit programs.

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

Are you sure "sum up two arays" means a[tid] + b[tid] instead of one thread sums the values of array a and the other array sums the values in array b?

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

Fatal error primes.lib: Not a valid library

Now that I think about it I think MASM is a 16-bit assembler so it won't be able to read libraries compiled with 32/64 bit compilers. Either use a 16-bit compiler that produces *.lib files or use a 32-bit MASM assembler.

have no idea how the assembler will know where to look for arguments of the printPrimes

Your assembly code has to push them onto the stack before calling the function then remove them after the function returns. Parameters are pushed from right to left in the parameter list, so the second parameter is pushed first, then the first parameter is pushed second. This can be changed by changing the C calling convention.

.model small
EXTRN printPrimes:PROC

.stack 100h

.data

.code

main proc
    mov dx, 2
    mov bx, 20
    push dx ; second parameter
    push bx ; first parameter
    call printPrimes
    add sp,4 ; pop the two parameters from the stack

    mov ah, 04ch
    int 21h
main endp
end main
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK masm only works with *.lib libraries built with Microsoft compilers or other compilers that create libraries in that format. Download and isntall the free Visual Studio 2013 Express.

ont libraries consist of header files?

They are compiled *.c files. You will have to create the header file manually yourself -- it's just a normal text file with *.h file extension.

Why is it, when i chose to write a "static library" that I was given a .c file?

Because that's where you write the executable code you want in the library. Header files consist of only function prototypes -- never (almost) executable code.

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

I heard a couple years ago Santa is no longer allowed to say HoHoHo because Ho is synonymous with Hore (prostitute).

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

You're original code was more like what I have in mind. Why did you change it?

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

Is it correct to say that, ptr[i].state = num; the '' dereferences the state pointer and not the array?

Yes, and you must make sure that memory has been allocated to state pointer.

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

All the code from lines 27 to 45 needs to be outside the loop started on line 21. You don't want to do all those calculations until the entire file has been read into the array.

while( project >> myFile[num] )
{
   num++;
}

// now do all the calculations here

Notice that project.eof() is not used because it will cause the last line of the file to be read twice.

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

ptr[i] is not a pointer, so you need to use the dot operator .

SetState() only needs one parameter, now twom In main() you would write this:

for(int i = 0; i < 100; i++)
    A[i].setState(n);

And setState() simplifies to just one line

void State::setState(int num)
{
        *state = num;
}        
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is Dict storing just the pointer address passed to it by addWord()? If yes, then that would explain why passing string literals such as "dog" and "cat" works while passing a character array doesn't. Dict needs to duplicate the string within the class so that the class has it's own copy.

For example: Here I'm assuming Word is a char pointer.

Dict::addWord(const char* w)
{
   Word = new strlen(w)+1;
   strcpy(Word,w);
}
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

What compiler are you using with QT? If it's gcc then probably not because the binary libraries are different.

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

Why make assumptions that may or may not be valid? Just do it the safe way and use a semaphore to synchronize access to the byte that contains those bits.

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

You can have a vector of vectors

vector< vector<MyClass> > printerList;

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

If it's anything like gcc then -o myfile in the makefile link statement should do it.

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

name is a single character, it is not an array (see line 7). Therefore you can only enter a one-character name. I doubt that is what you want. Also, Stud_Names is an array of pointers, so if you assign names to each pointer then all pointers will contain the same name. For example if you enter two student names, John and Mary, then Stud_Names[0] and Stud_Names[1] will both point to "Mary" because names contains the word "Mary".

In C++ you have a couple options:

1.change Stud_Names to be an array of std::string objects
std::string Stud_Names[100];

2.leave Stud_Names as an array of pointers, then call strdup to duplicate the names: This is the same as malloc and strcpy.

Stud_Names[i] = strdup(name);

Now for Stud_ID: This is a 1d array of 100 characters, yet you are treating it as a 2d array. Line 24 won't work because all you can enter for &Stud_ID[i]) is a single digit and the scanf statement uses "%c" not "%s".

scanf("%c", &Stud_ID[i]);

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

What language did you write the program in? You need to post the code you have written -- what you posted is ok, but doesn't help anyone to determine the cause of the problem.

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

You need to either use your compiler's debugger so that you can view the values of variables, or just put some print statements in the program to print out the value of variables. I can't tell you why if(hun == 3){ (line 51) doesn't work the way you think it should.

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

line 11: What??? That like saying while( 1 != 2) You could just delete lines 11 and 13 without changing that function.

unsigned int timer(){
    clock_t t;
    t = clock();
    unsigned int curtime = 0;
    return curtime += t;
}

And the above reduces to this:

unsigned int timer(){
    return clock();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first thing you should do is learn about tennis scoring rules. google for "tennis scoring rules" and you will come across this site, among several others.