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

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

If you want to replace an existing line then you need another temp file. You can't just simply replace an existing line in a text file because the length of the old and new lines may not be the same. If you attempt to do it anyway you will wind up with barbage in the line following the one you replace.

First, open the original file for reading and open a temp file for writing.

  • read a line from the original file
  • if the line is the one you want to replace then write the new line to temp file
  • otherwise if the line does not need to be replaced then write it to the temp file
  • repeat the above until the entire original file has been read
  • close both files
  • delete the original file
  • rename temp file to the same name as original file
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

No (link)

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

That's not entirely true, is it?

Yes it is entirely true. I did not say "we do not help with your homework", i said we don't do it for you.

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

We don't do homework for students.

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

Probably the fastest way to do that is to read all of file2 into an in-memory array(s). Then start reading file1 line by line. Read a line, search file2 array for employee ID, when found print to third file or to screen. Repeat that for each line in file1.

That might be optimized if both files are sorted by employee ID, such as you would not have to read file2 into memory first.

Exactly how to do that will depend on what programming language you will use.

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

Your file contains a lot of floats but your program is attempting to read them like integers. change myfile to be an array of floats, not integers.

You also have to change the signature of implied Task() like this:

void impliedTask(float *&myFile, float *&avg)

This is what I get after doing that. Don't know if the numbers are right or wrong because I don't know what the program is supposed to do.

97.99
4
61.23
49.32
30.22
80.19
21.67
86.23
30.34
62.1
38.3
93.9
42.5
13.4
68.3
===Start===

Number @index[0] is: 97.99
Sum @index[0] is: 97.99

Number @index[1] is: 4
Sum @index[1] is: 101.99

Number @index[2] is: 61.23
Sum @index[2] is: 163.22
Average index[0] is: 54.4

Number @index[3] is: 49.32
Sum @index[3] is: 49.32

Number @index[4] is: 30.22
Sum @index[4] is: 79.54

Number @index[5] is: 80.19
Sum @index[5] is: 159.73
Average index[1] is: 53.2

Number @index[6] is: 21.67
Sum @index[6] is: 21.67

Number @index[7] is: 86.23
Sum @index[7] is: 107.9

Number @index[8] is: 30.34
Sum @index[8] is: 138.24
Average index[2] is: 46

Number @index[9] is: 62.1
Sum @index[9] is: 62.1

Number @index[10] is: 38.3
Sum @index[10] is: 100.4

Number @index[11] is: 93.9
Sum @index[11] is: 194.3
Average index[3] is: 64.7

Number @index[12] is: 42.5
Sum @index[12] is: 42.5

Number @index[13] is: 13.4
Sum @index[13] is: 55.9

Number @index[14] is: 68.3
Sum @index[14] is: 124.2
Average index[4] is: 41.4
Press any key to continue . . .
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

Opsy daisy..

Never heard of it. oopsy daisy however is children's art or baby talk.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. Item One
  2. Item Two
  3. Item Three

    Log.i(MainActivity.class().getSimpleName(), SOME_MESSAGE); //info
    Log.d(MainActivity.class().getSimpleName(), SOME_MESSAGE); //debug
    Log.w(MainActivity.class().getSimpleName(), SOME_MESSAGE); //warning
    Log.e(MainActivity.class().getSimpleName(), SOME_MESSAGE); //error

List followed by code snippet does not render properly. Example

You're right. The Log... lines are in Code block but have no line numbers.

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

I would think ab^4c^2-d/m-n would be interpreted liks this: where ^ is power operation

a*(b^4)*(c^2)-(d/m)-n

In none of the math courses I took (or recall) did ^ represent bit operation. I only learned that when studying computer programming.

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

This is a dulicate thread.

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

Am not good at c++ programes at all

No one is when they first start. That's the whole point of learning.

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

got mad because of this quation

Why? because you think it is too difficult?

As with most programs just do it a little bit at a time. In this case the first step would be to create a menu in main(), when read all the data from the file into an array (probably array of integers).

Do you know the difference between linear and binary search algorithms? If not they should be explained in your textbook or google to get them. A linear search just simply starts at the beginning of the array and sequentially searches the array for a specific value, the array need not be sorted. The binary search requires the array to be sorted so you would have to Sort the array (menu option 3) before attempting the Binary Search (menu option 2).

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

We don't do your homework for you.

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

x % 10 will return the right most digit, for example if x = 15 then x%10 will return 5. Now put that in a loop, divide x by 10, to get all the digits

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

Probably the single most famous in USA would be the Grand Canyon.

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

line 124: Tests is an uninitialized pointer, attempting to read something into that pointer is destined to fail. Same with TestNo on line 133 -- no memory has been allocated to that pointer either.

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

//what would be output of this program.

Why don't you compile it, run it and see for your self what the output is.

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

b is a pointer to a vector, not to a Matrix2. vector's don't have transpose() method.

myMtrix2[0].transpost() may be what you want. Or if you want to call that method for each Matrix2 in the vector

for(auto x : myMatrix2)
{
   x.transpost();
}

The above requires c++11 compiliant compiler, and iterates through each of the vector's objects.

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

you could create an Android game or some other Android app.

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

The environment variable is set for only the current process, it does not affect system-wide global environment variables. You can simulate the same problem by doing the same in a command window, close the window, open another window and inspecting the environment variable you tried to set the first time. You will discover that the environment variable reverts to whatever it was before you tried to change it.

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

Yea, that was posted 4 years ago in this thread.

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

Did you decompress it after downloading?

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

Simple solution -- have Dani just email the mug to you.

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

Have you ever heard of nested loops? You have two loops, one inside the other. The other loops counts the rows in the 2d array, the innter loop counts the columns in each row.

int array[5][10]; // original array, 5 rows and 10 columns
int counters[5][2] = {0}; // 5 rows 2 columns
int rows = 5;
int cols = 10;
for(int i = 0; i < rows; i++)
{
   for(int j = 0; j < cols; j++)
   {
     if array[i][j] is already in counters array
     ...
   }
}   
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

That appears to be a tarball, but it has no extension so I don't know how to extract it.

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

If you are using a multi-process operating system such as MS-Windows or *nix there are lots of things outside the control of your program that could cause such behavior, such as some other process could consume more CPU time, or the os might be flushing data to the file system.

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

yes,

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

there are probably several ways to calculate the mode, but I think the simplest was is to create another 2d array, but this time the 1st dim contains one of the numbers from the original 2d array and the second dim contains a count of the number of times it appears in the original array.

So, to take just the first line of the data you posted
2 5 2 5 9 5 8 3 6 10

The 2d array would look like this

2 2
3 1
5 3
6 1
8 1
9 1
10 1

for each cell in the original array
    search new 2d array to see if it's already there
    if not, then add it and set it's count to 1
    if it is in the array, then increment it's count
end of loop

When done, just pick out the number with the greatest count, in the above case it would be 5.

You could probably simplify all that by using std::map instead of another array, but you may not have that choice.

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

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.