|
Why would you expect it to do anything else at no point do you chain the entries you just throw earlier entries away
I suggest you look at what List::add does because all you are doing is overwriting "head"
Contrast it to what List::AddNode does in the code above which does actually create a chain
In vino veritas
|
|
|
|
|
In addition to Leon's comments above ... think about the logic. A linked list must have a constant pointer to the start of the list, the 'head'. Each item in the list should contain one or more data items, and a pointer to the next item. The head pointer should only be allocated once, when the list is first created. Each subsequent item should be chained to the node at the end of the chain. You can keep a pointer to the last item, or let the add method iterate through the list to find it.
|
|
|
|
|
Quote: The AddNode and PrintList functions of the Linked list aren't working. (StaffMain.cpp).
I don't know about AddNode(), but your PrintList() function doesn't print anything: it calls the function staffDetails(), and maybe you intended that function to print out some information, but what it does instead is create a new object, which by the way creates a memory leak because you're not using the return value.
I think your problem is that your list stores factories, not staff, and that some(?) of the functions don't do what their name implies.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I am a beginner in programming and I am trying to solve this problem using queues. I can't seem to come with an idea to solve it.
Can you help please, it is a problem just to learn about how to approach queue problems.
This is the problem:
Tasks - Google Docs[^]
|
|
|
|
|
As with any problem, the approach is to examine the question carefully. Try to break it down into small parts and figure out how each part can be solved in order to feed into the next part. Draw diagrams on paper and do manual calculations to see what timings result.
I am not sure what is meant by " the quantity of rows and columns of the glade."
|
|
|
|
|
The solution is called a scheduler ... google "tutorial task scheduler in c"
In vino veritas
|
|
|
|
|
Hello
How do I check if XXX USB filter driver be installed by MFC?
Thanks
Vincent
|
|
|
|
|
|
I am trying to solve this problem through dynamic programming:
You are given a matrix of n rows and m columns. There’s an integer number on each cell of the board and the rabbit staying at the upper-left corner.
Collect the greatest sum possible, such that the rabbit can move in only two directions:
2 cells to the right and 1 cell down (x+2, y+1); 2 cells down and 1 cell to the right (x+1, y+2);
Input:
The first line contains two naturals n and m (1 ≤ n, m ≤ 10^3) – the quantity of rows and columns of the matrix.
The next n lines contain m numbers – the values of the matrix elements.
The upper-left corner’s coordinates are (1, 1), the lower-right corner’s – (n, m).
Output:
The greatest sum possibly collected. If the r rabbit can’t reach the lower-right corner, output «-».
Input1:
3 3
5 0 0
0 1 2
1 0 1
Output1:
-
Input2:
4 4
5 2 1 0
1 0 0 0
2 1 3 0
0 0 1 7
Output2:
13
This the code I tried to develop:
#include <iostream>
#include <algorithm>
using namespace std;
void findMaxSum(int *a[], int r, int c)
{
int **res = new int*[r];
for (int i = 0; i < r; i++) {
res[i] = new int[c];
for (int j = 0; j < c; j++)
res[i][j] = -1;
}
for (int i = 0; i < r-1; i++) {
for (int j = i; j < c-1; j++) {
res[i + 1][j + 2] = max(a[i][j] + a[i + 1][j + 2], res[i + 1][j + 2]);
res[i + 2][j + 1] = max(a[i][j] + a[i + 2][j + 1], res[i + 2][j + 1]);
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++)
cout << res[i][j] << " ";
cout << endl;
}
delete[] res;
}
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int r, c;
cin >> r >> c;
int **a = new int*[r];
for (int i = 0; i < r; i++) {
a[i] = new int[c];
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++)
cin >> a[i][j];
}
findMaxSum(a, r, c);
delete[] a;
return 0;
}
Could you help which right for or while loop to use to calculate such sum?
|
|
|
|
|
|
The Inseertobject does its job inserting a red bullet bitmap however it shifts over all the text by one byte as it puts a leading X'3F' I tried using ReplaceSel
shifting the text back one byte but upon display that line got duplicated
Thanks
|
|
|
|
|
You need to show the code and explain in more detail what you mean by "upon display that line got duplicated".
|
|
|
|
|
first off I am trying to write a front end to debugger sort of like visual studio I have a red bullet and the insert object works it places it in the first position of the buffer but the result is it shifts over the text in the rich buffer. The X'3F' seems to represent the red bullet bmp so I wrote code to shift everything over to the left 1 byte however seems like the lines get duplicated meaning
this is what in the rich edit before " STM R14,R12,12(R13) "
After the insertobject " LR R3,R15 "
" STM R14,R12,12(R13) "
" LR R3,R15
I cant cut and paste the rich edit display correctly but the insert object puts the bullet bmp where I want it, it just pushes the text to the right one byte thought if I wrote code to sh*t it over that would straighten it out but all did was display the STM line twice
This my code
myoleptr->InsertObject(&reobject);
int i;
RichListing->GetLine(RichListing->LineFromChar(-1), (LPTSTR)&buffer, 132);
for (i = 1; i < 132; i++)
buffer[i] = buffer[i + 1];
buffer before
0x00000004BEF4C2C0 3f 20 20 20 5f 20 20 20 20 20 20 20 32 33 20 20 20 20 20 20 20 20 30 30 30 30 30 30 20 20 20 20 ? _ 23 000000
0x00000004BEF4C2E0 20 20 20 20 20 20 20 20 20 53 54 4d 20 20 20 52 31 34 2c 52 31 32 2c 31 32 28 52 31 33 29 20 20 STM R14,R12,12(R13)
0x00000004BEF4C300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0x00000004BEF4C320 20 20 20 20 20 20 20 20 30 30 30 32 31 30 35 31 0d 00 cc cc cc cc cc cc cc cc cc cc cc cc cc cc 00021051..ÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C340 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C360 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C380 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C3A0 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
buffer after
0x00000004BEF4C2C0 3f 20 20 5f 20 20 20 20 20 20 20 32 33 20 20 20 20 20 20 20 20 30 30 30 30 30 30 20 20 20 20 20 ? _ 23 000000
0x00000004BEF4C2E0 20 20 20 20 20 20 20 20 53 54 4d 20 20 20 52 31 34 2c 52 31 32 2c 31 32 28 52 31 33 29 20 20 20 STM R14,R12,12(R13)
0x00000004BEF4C300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0x00000004BEF4C320 20 20 20 20 20 20 20 30 30 30 32 31 30 35 31 0d 00 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 00021051..ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C340 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
0x00000004BEF4C360 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
|
|
|
|
|
I am not sure that I can see what is wrong with that. Anything inserted into the control will take space and thus move everything else along.
|
|
|
|
|
Richard
I think the selection range has to be in line with the number of characters that are in
LPCTSTR lpszNewText,
of the null terminated string parameter of ReplaceSel
When you InsertObject a bitmap that bitmap depending on its size takes up a certain amount of characters depending among other things the size of font of the
current selection and the size of the bitmap. I am not sure if there is a some way to calculate this i.e. if you have a string and you want to know how many pixels it takes you do GetTextExtent. the REOBJECT structure doesn't seem to have parameters for the size of the bitmap like BITBLT I just played around with the string and the selection size and got it to align
|
|
|
|
|
Most image files and types have the size encoded in them. I don't know how you are loading the bitmap into the reobject variable but presumably you can check the source file/object.
|
|
|
|
|
CASE SOLVED AND CLOSED
FYI
As I pointed out in my recent post, which apparently did no good, this has been brought up before.
I am guilty of not going back to the original post.
Being repeatedly told that I am not sharing my code is getting old.
So - no need to be bothered again , let's just chalk this for yet another loop-sided discussion blaming the problem on me.
Cheers
CASE CLOSED
Re: Unexpected sequence of cout / perror in console output - C / C++ / MFC Discussion Boards[^]
SOLVED
It is acceptable and normal to direct standard output and standard error to the same destination, such as the text terminal. Messages appear in the same order as the program writes them, unless buffering is involved. For example, in common situations the standard error stream is unbuffered but the standard output stream is line-buffered; in this case, text written to standard error later may appear on the terminal earlier, if the standard output stream buffer is not yet full.
This is NOT a dupe, just an attempt to analyse / concentrate on specific problem.
The attached code execution clearly shows that the code is NOT run in sequence coded.
See line numbers - they are OUT of sequence.
The lines start with 40 and end with line 49
This is superficial, but annoying problem I would like to resolve.
Or just identify the reason for this behaviour.
BTW - inserting sleep(1) at various places "solves the problem".
cerr is used to output (stderr) to console in red AND WORKS just fine.
Maybe cerr and cout have conflicting "priority" or "4 core processor " in use is an issue.
cout << " START test area " << __LINE__ << endl;
cout << " START test area " << __LINE__ << endl;
cerr << "Function: " << __FUNCTION__ << " @line " << dec << __LINE__
<< endl;
cerr << "TRACE TEST Function: " << __FUNCTION__ << " @line " << dec
<< __LINE__ << endl;
cout << "\tEND test area " << __LINE__ << endl;
cout << "\tEND test area " << __LINE__ << endl;
START test area 40
START test area 41
Function: END test area 48
END test area 49
main @line 42
TRACE TEST Function: main @line 47
modified 22-Dec-19 9:44am.
|
|
|
|
|
I still cannot get the output in the "wrong" order. As mentioned below, I think there is a key piece of information that you have not shared with us.
|
|
|
|
|
Vaclav_ wrote: Being repeatedly told that I am not sharing my code is getting old. And there is an easy way to prevent that ...
|
|
|
|
|
SOLVED CASE CLOSED
Thanks for all the help from the group.
It is much appreciated.
Ask Mrs Google for "Eclipse ANSI" .
The question remains why it works without the 3rd part plug in when the app is crosscompiled.
I hope it will not bother the group if I revisit this , now multiple issue.
1. The attached C++ code DOES NOT execute in expected sequence.
Both perror output in red, which is expected , but out of expected sequence.
2. The setw works as expected.
3. The cout "escape sequence " DOES NOT change color and also outputs the sequence as "control characters".
It works well in crosscomplied code.
The code fails using tools implementing "standard" "hello word" on local machine.
This SAME code works as expected running after the application is crosscompiled for
"remote" machine. And has been working well for few months of development.
As far as I can tell - implementing "control / escape " characters in cout does not require anything special - iostream should work .
cout << " START test area " << __LINE__ << endl;
cout << __FUNCTION__ << endl;
cout << " START test area " << __LINE__ << endl;
cout << __FUNCTION__ << endl;
perror("TEST perror ");
cout << setw(30) << "\033[1;31mbold red text\033[0m\n";
perror("TEST perror ");
while(1);
<pre lang="text">
TEST perror : Success printed in red
TEST perror : Invalid argument printed in red
START test area 334
main
START test area 336
main
[1;31mbold red text[0m shifted , but no color change
modified 24-Dec-19 10:59am.
|
|
|
|
|
With cout you can do it directly without the escape code
cout << ansi::foreground_red << "bold red text" << ansi::foreground_white << endl;
In vino veritas
|
|
|
|
|
OK, stupid follow-up question.
How / where I activate "ansi"?
|
|
|
|
|
I just tried your code after correcting it, and it worked fine printing "bold red text" in bold red. What is that while(1); statement supposed to be for?
Also, why are your results shown in a different order to the actual instructions in your code sample?
|
|
|
|
|
I suppose asking to share your solution is out of the question.
Since this is a TEST code , the while(1); purpose is to stop code flow.
|
|
|
|
|
It's nothing special, just print the start test line, then two samples of perror, the first with no error, and the second with error 5.
cout << "Function: " << __FUNCTION__ << endl;
cout << " START test area " << __LINE__ << endl;
errno = 0;
perror("\033[1;31mTEST perror "); cout << "\033[0m\n"; errno = 5;
perror("\033[1;31mTEST perror ");
cout << "\033[0m\n";
Quote: Since this is a TEST code , the while(1); purpose is to stop code flow. Not sure what that means as there is nothing to stop.
|
|
|
|